You are here

C++ string handling

Read a line from a file: ( http://www.cplusplus.com/forum/beginner/8388/ )

#include 
#include 
#include 
using namespace std;

void main ()
{
        string STRING;
	ifstream infile;
	infile.open ("names.txt");
        while(!infile.eof) // To get you all the lines.
        {
	        getline(infile,STRING); // Saves the line in STRING.
	        cout 

Alternately we can open the file with: ( http://www.cplusplus.com/doc/tutorial/files/ )


  ifstream myfile ("example.txt");
  if (myfile.is_open())
  {
    while (! myfile.eof() )
    {
      getline (myfile,line);
      //
    }
    myfile.close();
  }

  else cout 
Topic: