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