istream的ignore使用,该如何解决

istream的ignore使用
C/C++ code
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没起作用?

------解决方案--------------------
我咋没问题
C/C++ code
int main()
{
    
 int val;

    ifstream ifile("1.dat");

    while (ifile >> val, !ifile.eof())
    {
        if (ifile.bad())
            throw runtime_error("IO System Error.");
        
        if (ifile.fail())
        {
            ifile.clear();
            ifile.ignore(20, ' ');
            continue;
        }

        cout << val << " ";
    }
    return 0;
}