/* handling incorrect interactive user input of numbers and end-of-file */ /* One technique... RJB Oct 2001 */ #include #include int main() { cout << "Please input some integers and finish with -1\n"; int in; //the input numbers string junk; // used to grab non digits bool done; // true when end of file is founs/input cin >> in; done = cin.eof(); //read ahead while(cin.fail() && !done) { cin.clear(); cin>>junk; cerr <<"\nError: "<> in; done = cin.eof(); }// !cin.fail or done while(in != -1 && !done) { while(cin.fail()) { cin.clear(); cin>>junk; cerr <<"\nError: "<> in; done = cin.eof(); }// not cin.fail cout << "\n" << in << "\n"; cin >> in; done = cin.eof(); }// in==-1 or done if(done) cout << "EOF"<