public member function
<ios> <iostream>

std::ios::rdstate

iostate rdstate() const;
Get error state flags
Returns the current internal error state flags of the stream.

The internal error state flags are automatically set by calls to input/output functions on the stream to signal certain errors.

Parameters

none

Return Value

An object of type ios_base::iostate that can contain any combination of the following state flag member constants:

iostate value
(member constant)
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.

Example

1
2
3
4
5
6
7
8
9
10
11
// getting the state of stream objects
#include <iostream>     // std::cerr
#include <fstream>      // std::ifstream

int main () {
  std::ifstream is;
  is.open ("test.txt");
  if ( (is.rdstate() & std::ifstream::failbit ) != 0 )
    std::cerr << "Error opening 'test.txt'\n";
  return 0;
}

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