C++ ifstream Read till the file end

Description

C++ ifstream Read till the file end

#include <fstream>
#include <iostream>
using namespace std;
int main()// w w  w.jav  a 2  s.c o m
{
   char ch;                       //character to read
   ifstream infile("TEST.TXT");   //create file for input
   while( infile )                //read until EOF or error
   {
      infile.get(ch);             //read character
      cout << ch;                 //display it
   }
   cout << endl;
   return 0;
}



PreviousNext

Related