string line,word; while(getline(cin,line)) { stringstream stream(line); cout<<stream.str()<<endl; while(stream>>word){cout<<word<<endl;}//stream相当于cin } return 0; } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 输入:shanghai no1 school 1989 输出:shanghi no1...
stringstream strm;创建自由的stringstream对象、 stringstream strm(s);创建存储s的副本的stringstream对象,其中s是string类型的对象 strm.str();返回strm中存储的string类型对象 strm.str(s);将string类型的s复制给strm,返回void getline(cin,str)//read a line and word from input into str; stringword; istrings...
{std::stringstream::pos_type posAtStartOfFirstLine = streamData.tellg();std::stringsecondLine;std::getline(streamData, firstLine);std::stringstream::pos_type posAtStartOfSecondLine = streamData.tellg();std::getline(streamData, secondLine);boolheader =true;while(header) {if(isValidTableData(...
word "Hello", from the stream, which is not "Hello world!". Instead of operator>>, use std::getline to read one line. -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing...