You enter
if (!(cin >> input_var))
if an error occurs while entering data from cin. If an error occurs, the error flag is set, and future attempts to get input will fail. That's why you need
cin.clear();
to get rid of the error flag. In addition, an input that has failed will sit in what I assume is a kind of buffer. When you try to get input again, it will read the same input in the buffer and it will work again. That's why you need
cin.ignore(10000,'\n');
It takes out 10,000 characters from the buffer, but stops if it encounters a new line (\ n). 10000 is just a total value.
quasiverse Feb 27 '11 at 5:44 2011-02-27 05:44
source share