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(), ‘\n‘); cout << ">> pls input a integer number:"; continue; } cout << "number = " << number << endl; } }
原文地址:https://www.cnblogs.com/cthon/p/9315269.html
时间: 2024-11-01 11:23:45