C++ ifstream Read string from file

Description

C++ ifstream Read string from file

#include <fstream>
#include <iostream>
using namespace std;
int main()/*from w w  w  .  j  a v a 2  s  .  c o m*/
{
   const int MAX = 80;              //size of buffer
   char buffer[MAX];                //character buffer
   ifstream infile("TEST.TXT");     //create file for input
   while( !infile.eof() )           //until end-of-file
   {
      infile.getline(buffer, MAX);  //read a line of text
      cout << buffer << endl;
   }
   return 0;
}



PreviousNext

Related