C++ string handling

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

#include < iostream>
#include < fstream>
#include < string>
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 << STRING; // Prints our STRING.
        }
	infile.close();
	system ("pause");
}

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 << "Unable to open file";