// Try it... #include #include #include using namespace std; int main(){ int i; while (true){ cout << "Enter a number: "; cin >> i; // cin is converted to 'a boolean value' // via an implicit conversion operator - while cin is in a good state cout << "We got: " << i << " " << endl; if (cin.good()) cout << "cin is good" << endl; else if (cin.eof()) cout << "cin is at EOF" << endl; // when typing Cntrl D else if (cin.fail()) cout << "cin has failed" << endl; // when typing a non-digit else if (cin.bad()) cout << "cin is in really bad shape" << endl; cin.clear(); cin.ignore(numeric_limits::max(), '\n'); // flush input } }