#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int integerValue;
// display results of cin functions
cout << "Before a bad input operation:"
<< "\ncin.rdstate(): " << cin.rdstate()
<< "\n cin.eof(): " << cin.eof()
<< "\n cin.fail(): " << cin.fail()
<< "\n cin.bad(): " << cin.bad()
<< "\n cin.good(): " << cin.good();
cin >> integerValue;
cout << endl;
cout << "After a bad input operation:"
<< "\ncin.rdstate(): " << cin.rdstate()
<< "\n cin.eof(): " << cin.eof()
<< "\n cin.fail(): " << cin.fail()
<< "\n cin.bad(): " << cin.bad()
<< "\n cin.good(): " << cin.good() << endl << endl;
cin.clear();
cout << "After cin.clear()" << "\ncin.fail(): " << cin.fail()
<< "\ncin.good(): " << cin.good() << endl;
return 0;
}
Before a bad input operation:
cin.rdstate(): 0
cin.eof(): 0
cin.fail(): 0
cin.bad(): 0
cin.good(): 12
After a bad input operation:
cin.rdstate(): 0
cin.eof(): 0
cin.fail(): 0
cin.bad(): 0
cin.good(): 1
After cin.clear()
cin.fail(): 0
cin.good(): 1