public member function
<ios> <iostream>

std::basic_ios::fail

bool fail() const;
Check whether failbit or badbit is set
Returns true if either (or both) the failbit or the badbit error state flags is set for the stream.

At least one of these flags is set when some error other than reaching the End-Of-File occurs during an input operation.

failbit is generally set by an operation when the error is related to the internal logic of the operation itself, and further operations on the stream may be possible. While badbit is generally set when the error involves the loss of integrity of the stream, which is likely to persist even if a different operation is attempted on the stream. badbit can be checked independently by calling member function bad:

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.

This function is a synonym of basic_ios::operator!.

Parameters

none

Return Value

true if badbit and/or failbit are 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