/* * @topic T00357 May 2 -- writing integers and reading integers * @brief Demonstrates <tt>ofstream ifstream eof() fail() clear() ios::trunc</tt> */ #include <iostream> #include <fstream> #include <string> using namespace std; int main () { // write into the file ofstream out; out.open( "D:/CIS155/dummy.txt", ios::out | ios::trunc ); out << "four \n 5 \n 6 \n seven"; out.close(); // read from the file ifstream inp; inp.open( "D:/CIS155/dummy.txt" ); while( inp.eof() != true ) { int value; inp >> value; if ( inp.fail() ) { inp.clear(); string str; inp >> str; cout << "FAILED: " << str << '\n'; } else { cout << " OKAY: " << value << '\n'; } } inp.close(); return 0; }