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
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)).