代码:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string s1, s2, s0;
cin >> s0;//遇到空格或换行结束输入
getline(cin, s1);//读取一整行输入
getline(cin, s2, ' ');//以空格结束输入
cout << "You inputed chars are: " << s0 << endl;
cout << "You inputed chars are: " << s1 << endl;
cout << "You inputed chars are: " << s2 << endl;
return 0;
}
输出结果: