You can use this:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main () {
string line;
ifstream myfile ("example.txt"); //change this to your file's name
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
cout << line << '\n';
}
myfile.close();
}
else
cout << "Unable to open file";
}
solved Read from file C++ (Simple) [duplicate]