string line, word;// will hold a line and word from input, rectively while (getline(cin, line)) { // read a line from the input into line // do per-line processing istringstream stream(line); // bind to stream to the line we read while (stream >> word) { // read a word from line // do per-word processing } }
[code="c++"] //用 getline 函数从输入读取整行内容。然后为了获得每行中的单词,将一个 //istringstream 对象与所读取的行绑定起来,这样只需要使用普通的 //string 输入操作符即可读出每行中的单词。 string line, word;// will hold a line and word from input, rect...