C++ IOS Library - rdstate


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


Following is the declaration for ios::rdstate function.

iostate rdstate() const;



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)

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
failbitLogical error on i/o operation false false true false failbit
badbitRead/writing error on i/o operation false false true true badbit


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.


In below example is shown for ios::rdstate.

#include <iostream>     
#include <fstream>      

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;