<<< I/O Stream States | Index | Recovering from fail( ) State >>> |
#include <iostream> using std::stream; int main() { int value = 0; cin >> value; if ( !cin ) { // cin is not good, more checks required: if ( cin.bad() ) { // cin is corrupted return 1; // signal error back to the operating system } if ( cin.eof() ) { // nothing to do: we want all inputs to end like this! return 0; // signal success to the operating system } if ( cin.fail() ) { cin.clear(); // prepare for more input... // do something to recover... } } // use value, everything is ok return 0; }
<<< I/O Stream States | Index | Recovering from fail( ) State >>> |