cin.eof() functionality

前端 未结 8 1163
夕颜
夕颜 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 13:58

    std::cin.eof() tests for end-of-file (hence eof), not for errors. For error checking use !std::cin.good(), the built-in conversion operator (if(std::cin)) or the boolean negation operator (if(!std::cin)).

提交回复
热议问题