ios::clear
void clear ( iostate state = goodbit );
ios
  cplusplus.com  

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:
  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();
  }

  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