I am looking through the istream
class and I don't see a method that cleans completely the buffer and sets the input to be ready for a next "clean" input.
I defined the extraction operator for my class, and in my main program I ask the user for an input, like this:
while (true) {
try {
cout << "Enter input: ";
MyClass c;
cin >> c;
return c;
} catch(const MyException& e) {
cerr << "Error\n";
}
}
If I enter an unexpected incorrect input I am trapped in an infinite loop.
In my overriden extractin method I control when the input is not correct and the exception is thrown, all this is ok. I just want to also clean the istream
object so I prevent the infinite loop.