Sorry for the noobish question here, but I am just learning C++ and I am looking for the standard way of dealing with this problem. I am using VS2005.
Given a program:
#include <iostream>
using namespace std;
int main( )
{
while ( true )
{
cout << "enter anything but an integer and watch me loop." << endl;
int i;
cin >> i;
}
return 0;
}
If you enter anything but an integer the program will never allow you to enter anything again. Now, I realize that this is because there is input left on the stream after the format fails, so each call to cin << i just reads up to the next end line (I think). How do you guys clear out the stream or deal with this problem? It must be pretty common.