关于iostream中clear函数的疑惑
程序代码如下:程序代码:
#include <iostream> using namespace std; int main() { int ival; while (cin >> ival, !cin.eof()) { if (cin.bad()) { // throw runtime_error("IO stream corrupted"); } if (cin.fail()) { cerr << "bad data, try again" << endl; cin.clear(istream::failbit); continue; } cout << ival << "\t"; } return 0;当cin.fail()= true时,用cin.clear(istream::failbit)处理后,后续就不能再读入数据ival了,请问这是怎么回事呢?如果想继续读入ival,怎么处理呢?