istream的ignore使用
int _tmain(int argc, _TCHAR* argv[])
{
int val;
ifstream ifile("1.dat");
while (ifile >> val, !ifile.eof())
{
if (ifile.bad())
throw runtime_error("IO System Error.");
if (ifile.fail())
{
cerr << "bad val, try again";
ifile.clear(ifstream::failbit);
ifile.ignore(20, ' ');
continue;
}
cout << val;
}
return 0;
}文件1.dat的内容很简单:
1 s 2
为什么执行的时候还是死循环,ifile.ignore没起作用?
...全文


