运行结果:

在 C 中可以使用 gets() , 在C++ 中一般使用 cin.getline(), getline(),代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
char str[100];
// C 中使用
gets(str);
printf("%s\n", str);
// C++ 使用
cin.getline(str, 100);
cout << str << endl;
string line;
getline(cin, line);
cout << line << endl;
system("pause");
return 0;
}