#include #include using namespace std; int main() { { ofstream full("/dev/full"); full << "wibble" << endl; cout << "after write to /dev/full:\n" << " fail: " << full.fail() << '\n' << " bad: " << full.bad() << '\n' << " eof: " << full.eof() << '\n' << " good: " << full.good() << '\n'; } { int i; ifstream empty("/dev/null"); empty >> i; cout << "after integer read from /dev/null:\n" << " fail: " << empty.fail() << '\n' << " bad: " << empty.bad() << '\n' << " eof: " << empty.eof() << '\n' << " good: " << empty.good() << '\n'; } { string s; ifstream empty("/dev/null"); getline(empty, s); cout << "after getline from /dev/null:\n" << " fail: " << empty.fail() << '\n' << " bad: " << empty.bad() << '\n' << " eof: " << empty.eof() << '\n' << " good: " << empty.good() << '\n'; } { int i; ifstream zero("/dev/zero"); zero >> i; cout << "after integer read from /dev/zero:\n" << " fail: " << zero.fail() << '\n' << " bad: " << zero.bad() << '\n' << " eof: " << zero.eof() << '\n' << " good: " << zero.good() << '\n'; } { int i; close(0); cin >> i; cout << "after integer read from a bad FD:\n" << " fail: " << cin.fail() << '\n' << " bad: " << cin.bad() << '\n' << " eof: " << cin.eof() << '\n' << " good: " << cin.good() << '\n'; } return 0; }