64,648
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <stdexcept>
#include <cstdlib>
using namespace std;
int main()
{
int ival;
cout << "Enter ival" << endl;
while (cin >> ival, !cin.eof())
{
if (cin.bad()) //发生系统级故障时
{
throw runtime_error("IO Stream corrupted");
}
if (cin.fail())//读取的数据类型不匹配时
cerr << "bad data, try again";
cin.clear(istream::failbit);
cin.sync();
break;
}
return EXIT_SUCCESS;
system("pause");
}