#include #include #include int main() { string filedata; ifstream myfile("filesin.txt"); cout << "Just opened file" << endl; if (myfile.good()) cout << "Good bit set" << endl; if (myfile.bad()) cout << "Bad bit set" << endl; if (myfile.fail()) cout << "Fail bit set" << endl; if (myfile.eof()) cout << "Eof bit set" << endl; cout << endl; myfile >> filedata; cout << "Just read an item" << endl; if (myfile.good()) cout << "Good bit set" << endl; if (myfile.bad()) cout << "Bad bit set" << endl; if (myfile.fail()) cout << "Fail bit set" << endl; if (myfile.eof()) cout << "Eof bit set" << endl; cout << endl; myfile >> filedata; cout << "Trying to read another item" << endl; if (myfile.good()) cout << "Good bit set" << endl; if (myfile.bad()) cout << "Bad bit set" << endl; if (myfile.fail()) cout << "Fail bit set" << endl; if (myfile.eof()) cout << "Eof bit set" << endl; cout << endl; myfile.close(); // This file doesn't exist myfile.open("filesin3.txt"); cout << "Trying to open non-existent file" << endl; if (myfile.good()) cout << "Good bit set" << endl; if (myfile.bad()) cout << "Bad bit set" << endl; if (myfile.fail()) cout << "Fail bit set" << endl; if (myfile.eof()) cout << "Eof bit set" << endl; cout << endl; myfile >> filedata; cout << "Trying to read from it" << endl; if (myfile.good()) cout << "Good bit set" << endl; if (myfile.bad()) cout << "Bad bit set" << endl; if (myfile.fail()) cout << "Fail bit set" << endl; if (myfile.eof()) cout << "Eof bit set" << endl; cout << endl; myfile.close(); cout << "Trying to close it" << endl; if (myfile.good()) cout << "Good bit set" << endl; if (myfile.bad()) cout << "Bad bit set" << endl; if (myfile.fail()) cout << "Fail bit set" << endl; if (myfile.eof()) cout << "Eof bit set" << endl; return 0; }