After reading in a bad value, cin is in a failed state. You must reset it.
You must clear the error flag and free the buffer. In this way:
cin.clear();
cin.ignore(std::numeric_limits<streamsize>::max(), '\n');
The second call will flush the input buffer of any data that might be there to prepare you for the next cin call.
, " ", .
inline void reset( std::istream & is )
{
is.clear();
is.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
}
istream, cin, - . , , .