public member function

std::ios::rdstate

<ios>
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 to signal certain types of errors that happened during their execution.

Parameters

none

Return Value

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


flag valueindicates
eofbitEnd-Of-File reached while performing an extracting operation on an input stream.
failbitThe last input operation failed because of an error related to the internal logic of the operation itself.
badbitError due to the failure of an input/output operation on the stream buffer.
goodbitNo error. Represents the absence of all the above (the value zero).

These values are declared as static member constants in the parent class ios_base.

To check for a specific state other than goodbit with this member function, this can be done by checking if the corresponding bit is set using the & operator (bitwise AND) with its specific bitmask, because more than one error state could be set at the same time.

To check for individual state flags more easily, the member functions eof, fail, bad and good exist.

Example

1
2
3
4
5
6
7
8
9
10
11
12
// getting state of stream object
#include <iostream>
#include <fstream>
using namespace std;

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


Basic template member declaration

( basic_ios<charT,traits> )
 
iostate rdstate () const;


See also