1int number;
2
3cout << "Enter an Integer: ";
4cin >> number;
5
6// User types any char or string of length < 100
7
8// Because input stream is in a failed state, cin will be evaluated to false
9while ( !cin )
10{
11 cin.clear (); // Restore input stream to working state
12 cin.ignore ( 100 , '\n' ); // Get rid of any garbage that user might have entered
13 cout << "I said enter an integer, Dumbass. Try again: ";
14 cin >> number; // After cin is restored and any garbage in the stream has been cleared, store user input in number again
15}