在使用while(cin >> word)如何結束輸入

在練習時用while(cin >> word),輸入時,嘗試用ctrl+c,enter, space都不可以結束輸入,最後經過google才知道用ctrl+z,之後再用Enter結束,以此記錄。

#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
   string word;
	vector<string> text;
	cout << "enter word:" << endl;
	while (cin >> word)
	{
		text.push_back(word);
	}
	
	for (vector<string>::iterator iter = text.begin(); iter != text.end(); ++iter)
	{
		cout  << *iter << endl;
	}

	system("PAUSE");
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章