Clears iostate field.
void clear
(iostate state = goodbit) throw failure;
Use clear() to reset the failbit, eofbit or a badbit that may have been set inadvertently when you wish to override for continuation of your processing. Post-condition of clear is the argument and is equal to rdstate().
If rdstate() and exceptions() != 0 an exception is thrown.
No value is returned.
// The file ewl-test contains: // ABCDEFGH #include <iostream> #include <fstream> #include <cstdlib> char * inFile = "ewl-test"; using namespace std; void status(ifstream &in); int main() { ifstream in(inFile); if(!in.is_open()) { cout << "could not open file for input"; exit(1); } int count = 0; int c; while((c = in.get()) != EOF) { if(count++ == 4) { // simulate a failed state in.setstate(ios::failbit); in.clear(); } status(in); } status(in); in.close(); return 0; } void status(ifstream &in) { // note: eof() is not needed in this example // if(in.eof()) cout << "EOF encountered \n" if(in.fail()) cout << "Non-Fatal I/O Error \n"; if(in.good()) cout << "GoodBit set \n"; if(in.bad()) cout << "Fatal I/O Error \n"; }
Result:
GoodBit set GoodBit set GoodBit set GoodBit set GoodBit set GoodBit set GoodBit set GoodBit set Non-Fatal I/O Error