Use this collection of methods to test for (or signal) errors and other exceptional conditions of streams:
ios::fail
is not true). For example, you might ask for input on cin
only if all prior output operations succeeded:
if (cout) { // Everything OK so far cin >> new_value; ... }
!
returns true if ios::fail
is true (an operation has failed). For example, you might issue an error message if input failed:
if (!cin) { // Oops cerr << "Eh?\n"; }
iostate
. You can test for any combination of
goodbit
eofbit
failbit
badbit
ios::set
.
See ios::clear
to set the stream state without regard to existing state flags. See ios::good
, ios::eof
, ios::fail
, and ios::bad
, to test the state.
ios::badbit
is set.)
ios::eofbit
is set.)
ios::failbit
or ios::badbit
is set.)
ios::clear
with no argument, in which case the state is set to good
(no errors pending).
See ios::good
, ios::eof
, ios::fail
, and ios::bad
, to test the state; see ios::set
or ios::setstate
for an alternative way of setting the state.