积极答复者
关于C++中输入操作符(>>)返回输入流对象的的问题

问题
-
我练习编写了下面的一段小程序
#include <iostream> #include <string> #include <vector> using std::cout; using std::cin; using std::endl; using std::string; using std::vector; int main() { string word; vector<string> text; while (cin >> word) { text.push_back(word); } for(vector<string>::size_type sx = 0; sx != text.size(); ++sx) { cout << text[sx] << endl; } return 0; }
却发现程序停在while循环中出不来。调试的过程中发现输入流对象始终有效,即使如入换行符依旧是这样。这让我非常困惑。我想问问如何才能跳出while循环呢?