难道是不能直接判断cin是否到结尾,应该输入Ctrl+z 再按回车,这样才能退出?

string tmp;while(1)
{
cin >> tmp;if(tmp[0] == '\0')break;cout << "输出字符:" << tmp << endl;}

我使用了 cin.eof() 和 cin.good() 都不可以,在win7平台下,mingw编译 我刚刚开始学习C++,希望高人帮帮忙


神不在的星期二
浏览 140回答 2
2回答

千巷猫影

#include <iostream>#include <string>using namespace std;int main(){&nbsp; &nbsp; &nbsp; &nbsp; string tmp = "";&nbsp; &nbsp; &nbsp; &nbsp; while(cin >> tmp){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cout << "输出字符:" << tmp << endl;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return 0;}

MMMHUHU

while( cin >> tmp ) cout << tmp << endl ;
打开App,查看更多内容
随时随地看视频慕课网APP