public member function
<ios> <iostream>
std::ios::fail
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) | 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 |
failbit | Logical error on i/o operation | false | false | true | false | failbit |
badbit | Read/writing error on i/o operation | false | false | true | true | badbit |
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
- ios_base::iostate
- Type for stream state flags (public member type
)
- ios::good
- Check whether state of stream is good (public member function
)
- ios::bad
- Check whether badbit is set (public member function
)
- ios::eof
- Check whether eofbit is set (public member function
)
- ios::rdstate
- Get error state flags (public member function
)
- ios::clear
- Set error state flags (public member function
)