Home

iostate

iostate is a type used in the C++ standard library to represent the state of an input/output stream. Defined within ios_base, it tracks whether a stream is in a good condition or has encountered errors. The type is used by standard stream classes such as std::istream, std::ostream, std::iostream, and their concrete implementations (for example, std::cin, std::cout, std::ifstream, std::ostringstream) to report the result of I/O operations.

The iostate type is a bitmask that combines four distinct flags: goodbit, eofbit, failbit, and badbit. goodbit

State of a stream can be checked with member functions such as good(), eof(), fail(), and bad().

The iostate value may be manipulated with clear() calls to reset or modify specific bits, and it

In summary, iostate provides a standardized way to represent and inspect the success or failure of I/O

indicates
no
error
and
is
typically
zero.
eofbit
signals
end-of-file.
failbit
indicates
a
logical
I/O
error
or
that
a
formatted
input
operation
failed.
badbit
indicates
a
more
serious
error
that
may
reflect
a
loss
of
integrity
of
the
stream.
These
bits
can
be
combined;
for
instance,
a
stream
may
be
at
end-of-file
and
fail
at
the
same
time.
While
exact
numeric
values
are
implementation-dependent,
they
are
designed
as
distinct
bit
patterns
(commonly
with
nonzero
values
for
eofbit,
failbit,
and
badbit).
good()
returns
true
when
no
error
bits
are
set
(the
stream
is
in
a
good
state).
eof()
reports
whether
eofbit
is
set.
fail()
indicates
either
failbit
or
badbit
is
set,
and
bad()
indicates
badbit
is
set.
Streams
can
also
be
tested
in
boolean
contexts,
which
reflect
their
overall
good
or
error
state.
can
be
used
with
the
exceptions
mechanism
via
ios_base::exceptions
to
trigger
exceptions
(ios_base::failure)
when
certain
bits
become
set
after
operations.
operations
within
the
C++
standard
library.