how to get the "failure flag"

I've read that cin.clear() would clear any bad flags ( if set )

For e.g.,
1
2
3
4
  int x;

  cin >> x; // a non-numeric value is entered ( i.e., 'r')
  cin.clear();
;

In the piece of code above, when 'r' is entered when an integer is expected, some failure flags are set. So the question is, how do I get the value of that flag. In other word, how do I know if these flags were set?

I attempted to do something like
bool flag = cin.bad() ... but obviously, it's not correct~! ...
Using cin.bad(), .fail(), .good() and .eof() should work.
You can also use rdstate: http://www.cplusplus.com/reference/iostream/ios/rdstate/
Topic archived. No new replies allowed.