将整行读入到line后,istringstream可以将line按照空格分块输出。
#include <iostream>
#include <sstream>
using namespace std;
int main(){
string line, str;
while(getline(cin, line)){
istringstream sm(line);
while(sm >> str)
cout << str << endl;
}
return 0;
}
/* input:
a b c dddd
ee fff g
*/
/* output:
a
b
c
dddd
ee
fff
g
*/