void test1(void) { int number; cout << ">> pls input a integer number:"; while(cin >> number, !cin.eof()) { if(cin.bad()) { cout << "stream has corrupted!" << endl; return; } else if (cin.fail()) { cin.clear(); cin.ignore(std::numeric_limits<std::streamsize>::max(), ' '); cout << ">> pls input a integer number:"; continue; } cout << "number = " << number << endl; } }