Read string from file - C++ File Stream

C++ examples for File Stream:stream

Description

Read string from file

Demo Code

#include <fstream>
#include <iostream>
using namespace std;
int main()//from   w ww .java2 s.  com
{
   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;
}

Result


Related Tutorials