c_-_c_files:file_status
C - C++ Files - File status
#include <iostream> #include <fstream> using namespace std; void checkstatus(ifstream &in); int main(int argc, char *argv[]) { ifstream in("test.txt"); char c; while(in.get(c)) { checkstatus(in); } checkstatus(in); // check final status in.close(); return 0; } void checkstatus(ifstream &in) { ios::iostate i; i = in.rdstate(); if(i & ios::eofbit) cout << "EOF encountered\n"; else if(i & ios::failbit) cout << "Non-Fatal I/O error\n"; else if(i & ios::badbit) cout << "Fatal I/O error\n"; }
c_-_c_files/file_status.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1