的我使用以下代碼:cin.get()不失控環
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
char c ;
c = cin.get() ;
do {
cout.put(c) ;
c = cin.get() ;
} while (!cin.eof()) ;
cout << "coming out!" << endl;
return 0;
}
問題的上面的代碼,其不失控循環,這意味着其不打印的「出山」。任何人都可以幫助它爲什麼如此?我在mac和linux上測試這個程序。
感謝
儘管你的答案while(c!='\ n')在終端上工作,但是當我嘗試使用文件輸入時,它會卡住。不管怎麼說,多謝拉。 – itsaboutcode 2010-07-01 16:06:34
添加'&&!cin.eof()'。 – SLaks 2010-07-01 16:08:34
你是偉人! – itsaboutcode 2010-07-01 16:15:18