Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile, line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
...or even better would be...
Code:
#include <iostream>
#include <fstream>
#include <string>
int main ()
{
std::string line;
std::ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
std::getline (myfile, line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
Google namespaces.