Mega Code Archive

 
Categories / C++ Tutorial / File Stream
 

Display a file using ifstream get()

#include <iostream>  #include <fstream>  using namespace std;    int main(int argc, char *argv[])  {    char ch;      ifstream in("test", ios::in | ios::binary);    if(!in) {      cout << "Cannot open file.\n";      return 1;    }      while(in) { // in will be false when eof is reached      in.get(ch);      if(in) cout << ch;    }      in.close();      return 0;  } hello