cin.eof() functionality

前端 未结 8 1171
夕颜
夕颜 2021-01-11 13:40

I understand that cin.eof() tests the stream format. And while giving input, end of character is not reached when there is wrong in the input. I tested

8条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-11 14:10

    EOF stands for e nd o f f ile. std::cin is the standard input. The standard input, under normal circumstances, never reaches the end: you can always just type some more.

    Further, .eof() only returns true if an input operation has already failed because of trying to read past the end of the file. The program actually can't tell that it's "at the end of file"; that is, the only way it can find out that the next attempt to read data will fail is by actually making the attempt.

提交回复
热议问题