public member function
<ios> <iostream>

std::ios::bad

bool bad() const;
Check whether badbit is set
Returns true if the badbit error state flag is set for the stream.

This flag is set by operations performed on the stream when an error occurs while read or writing data, generally causing the loss of integrity of the stream.

Notice that this function is not the exact opposite of good, which checks whether none of the error flags (eofbit, failbit and badbit) are set, and not only badbit:

iostate value
(member constants)
indicatesfunctions to check state flags
good()eof()fail()bad()rdstate()
goodbitNo errors (zero value iostate)truefalsefalsefalsegoodbit
eofbitEnd-of-File reached on input operationfalsetruefalsefalseeofbit
failbitLogical error on i/o operationfalsefalsetruefalsefailbit
badbitRead/writing error on i/o operationfalsefalsetruetruebadbit
eofbit, failbit and badbit are member constants with implementation-defined values that can be combined (as if with the bitwise OR operator).
goodbit is zero, indicating that none of the other bits is set.

Parameters

none

Return Value

true if the stream's badbit error state flag is set.
false otherwise.

Data races

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

Exception safety

Strong guarantee: if an exception is thrown, there are no changes in the stream.

See also