<<< Recovering from fail( ) State | Index | State Check Example >>> |
#include <iostream>
using std::cin;
int main()
{
int value = 0;
if ( !( cin >> value ) ) {
// cin is not good, more checks required...
if ( cin.bad() ) {
// stream is corrupted...
}
if ( cin.eof() ) {
// no data is available...
}
if ( cin.fail() ) {
cin.clear(); // go back to good state...
// do something to recover...
}
}
// use value, everything is ok
return 0;
}
<<< Recovering from fail( ) State | Index | State Check Example >>> |