A working example (compile it with your favourite compiler/IDE to obtain the executable):
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
const string Filename{"out.txt"};
{
ofstream ofs{Filename};
ofs << "hi there" << endl;
}
ifstream ifs(Filename);
while (ifs)
{
string line;
getline(ifs, line);
cout << line << endl;
}
}