C++ IOS Library - setstate


It is used to check Set error state flag. Modifies the current internal error state flags by combining the current flags with those in argument state (as if performing a bitwise OR operation).Any error bitflag already set is not cleared. See member clear for a similar function that does. . In the case that no stream buffer is associated with the stream when this function is called, the badbit flag is automatically set (no matter the value for that bit passed in argument state).


Following is the declaration for ios::setstate function.

void setstate (iostate state);


state − An object of type ios_base::iostate that can take as value any combination of the following member constants −

iostate value

(member constant)

indicates functions to check state flags
good() eof() fail() bad() rdstate()
goodbit No errors (zero value iostate) true false false false goodbit
eofbit End-of-File reached on input operation false true false false eofbit
failbitLogical error on i/o operation false false true false failbit
badbitRead/writing error on i/o operation false false true true badbit

Return Value



Basic guarantee − if an exception is thrown, the stream is in a valid state. It throws an exception of member type failure if the resulting error state flag is not goodbit and member exceptions was set throw for that state.

Data Races

Modifies the stream object.

Concurrent access to the same stream object may cause data races.