Read from file (ifstream)

For pure input files the class ifstream is suitable.

Open a file

ifstream myFile;
myFile.open(filename, ios::in);

Example

#include <fstream>
#include <iostream>
using namespace std;

int main() {
    string str;
    ifstream myFile;
    myFile.open("textfile.txt", ios::in);
    while (!myFile.eof()) {
        getline(myFile, str);
        cout << str << endl;
    }
    myFile.close();

    return 0;
}
Output
First line in text file
Second line in text file
Third line in text file