public member function
<ios> <iostream>


bool fail() const;
Check whether either 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 an error 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; 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
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.

Reaching the End-of-File sets the eofbit. But note that operations that reach the End-of-File may also set the failbit if this makes them fail (thus setting both eofbit and failbit).

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



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