For pure input files the class ifstream
is suitable.
ifstream myFile;
myFile.open(filename, ios::in);
#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;
}
First line in text file
Second line in text file
Third line in text file