该程序反复读取第一行。我到处都在寻找答案,我了解到在按“ Enter”后,它应该阅读下一行。为什么不呢?
#include<iostream>
#include<sstream>
using namespace std;
int main() {
stringstream ss;
string line, str;
while(getline(cin, line) ){
ss.str(line);
ss >> str;
cout << str << endl;
cout << endl;
}
return 0;
}
输出看起来像这样
Hello
Hello
World!
Hello
and
Hello
again
Hello
Hello
Hello