void clear ( iostate state = goodbit );

Set control states.
  Sets a new value for the control state ignoring the existing value.


  An object of type ios_base::iostate that can take as value any combination of the following state flag member constants:
  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.


// clearing errors
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  char buffer [80];
  fstream myfile; ("test.txt",fstream::in);

  myfile << "test";
  if (
    cout << "Error writing to test.txt\n";

  myfile.getline (buffer,80);
  cout << buffer << " successfully read from file.\n";

  return 0;
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 );

See also.
  fail, good, bad, eof, rdstate
  ios class

© The C++ Resources Network, 2001