End of file sign : File Status « File « C++






End of file sign

 

#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char *argv[])
{
  char ch;

  if(argc!=2) {
    cout << "PR: <filename>\n";
    return 1;
  }

  ifstream in(argv[1]);

  if(!in) {
    cout << "Cannot open input file.\n";
    return 1;
  }

  while(!in.eof()) { 
    in.get(ch);
    // check for error
    if(!in.good() && !in.eof()) {
      cout << "I/O Error...terminating\n";
      return 1;
    }
    cout << ch;
  }

  in.close();

  return 0;
}

           
         
  








Related examples in the same category

1.Check file status
2.I/O Status
3.The string pointed to by mode determines how the file will be opened. The following table shows the legal values for mode. (Strings like ?+b?may also be represented as ?b+.?