I just found a comment in this answer saying that using iostream::eof
in a loop condition is "almost certainly wrong". 我剛剛在此答案中找到一條評論,說在循環條件下使用iostream::eof
是「幾乎確定是錯誤的」。 I generally use something like while(cin>>n)
- which I guess implicitly checks for EOF. 我一般使用while(cin>>n)
類的東西-我猜它隱式地檢查EOF。 ios
Why is checking for eof explicitly using while (!cin.eof())
wrong? 爲何顯式地使用while (!cin.eof())
檢查eof是錯誤的? ide
How is it different from using scanf("...",...)!=EOF
in C (which I often use with no problems)? 與在C語言中使用scanf("...",...)!=EOF
有什麼不一樣(我常常會毫無問題地使用它)? oop