cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : ios : rdstate
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
IOstream Library
manipulators
classes:
· filebuf
· fstream
· ifstream
· ios
· iostream
· ios_base
· istream
· istringstream
· ofstream
· ostream
· ostringstream
· streambuf
· stringbuf
· stringstream
objects:
· cerr
· cin
· clog
· cout
types:
· fpos
· streamoff
· streampos
· streamsize
ios
· ios::ios
· ios::~ios
member functions:
· ios::bad
· ios::clear
· ios::copyfmt
· ios::eof
· ios::exceptions
· ios::fail
· ios::fill
· ios::good
· ios::imbue
· ios::init
· ios::narrow
· ios::operator!
· ios::operator void*
· ios::rdbuf
· ios::rdstate
· ios::setstate
· ios::tie
· ios::widen

-

ios::rdstate public member function
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

// 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

ios::fail Check if either failbit or badbit is set (public member function)
ios::good Check if the state of the stream is good for i/o operations. (public member function)
ios::bad Check if badbit is set (public member function)
ios::eof Check if eofbit is set (public member function)
ios::clear Set error state flags (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us