|
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 value | indicates |
eofbit | End-Of-File reached while performing an extracting operation on an input stream. |
failbit | The last input operation failed because of an error related to the internal logic of the operation itself. |
badbit | Error due to the failure of an input/output operation on the stream buffer. |
goodbit | No 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
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) |
|