void setstate ( iostate state );
Set control state.
Modifies the current control state value by adding (bitwise OR) the error state flags passed as paremeter to the current state.
Any error bit already set is not cleared. If you want to modify the state flags without keeping the current value use clear instead.
The effect of this function is as to call:
clear ( rdstate() | state );
Parameters.
state
An object of type ios_base::iostate that can take as value any combination of the following state flag member constants:
badbit (critical error in stream buffer)
eofbit (End-Of-File reached while extracting)
failbit (failure extracting from stream)
These are static member constants inherited from ios_base. You may combine more than one state flag bitmask using the bitwise | (or) operator.
Return Value.
none
Basic template member declaration ( basic_ios<charT,traits> ):
void setstate ( iostate state );
ios:: clear
void clear ( iostate state = goodbit );
Set control states.
Sets a new value for the control state ignoring the existing value.
Parameters.
state
An object of type ios_base::iostate that can take as value any combination of the following state flag member constants:
badbit (critical error in stream buffer)
eofbit (End-Of-File reached while extracting)
failbit (failure extracting from stream)
goodbit (no error condition, represents the absence of the above bits)
These are static member constants inherited from ios_base. You may combine more than one state flag bitmask using the bitwise | (or) operator.
If this parameter is not specified, goodbit is assumed so any error state is cleared.
Return Value.
none
Example.
// clearing errors
#include <iostream>
#include <fstream>
using namespace std;
int main () {
char buffer [80];
fstream myfile;
myfile.open ("test.txt",fstream::in);
myfile << "test";
if (myfile.fail())
{
cout << "Error writing to test.txt\n";
myfile.clear();
}
In this example myfile is open for input operations, but we commit an output operation on it, so failbit is set. The example calls then clear in order that further operations like getline can be successfully performed on myfile.
Basic template member declaration ( basic_ios<charT,traits> ):
void clear ( iostate state = goodbit );