C++ IOS Library - fail



Description

It is used to check whether either failbit or badbit is set. 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)

indicates functions to check state flags
good() eof() fail() bad() rdstate()
goodbitNo errors (zero value iostate) true false false false goodbit
eofbitEnd-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

Declaration

Following is the declaration for ios::fail function.

bool fail() const;

Parameters

none

Return Value

true if badbit and/or failbit are set or else false otherwise.

Exceptions

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

Data Races

Accesses the stream object.

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

ios.htm
Advertisements