By default, std::basic_istream::ignore()
ignores only 1 character:
basic_istream& ignore( std::streamsize count = 1, int_type delim = Traits::eof() );
(From http://en.cppreference.com/w/cpp/io/basic_istream/ignore)
More idiomatic use for your case seems to be the one from the example there:
cin.ignore(std::numeric_limits::max(), '\n');
Also, note that you want to call clear()
before the ignore()
call, so the input extraction of ignore()
will succeed instead of returning immediately.