code:
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
int main () {
ofstream ofile ("D:\\example.txt");
if (ofile.is_open())
{
ofile << "This is a line.\n";
ofile << "This is another line.\n";
ofile.close();
}
else cout << "Unable to open file";
string line;
ifstream ifile ("D:\\example.txt");
if (ifile.is_open())
{
while ( getline (ifile,line) )
{
cout << line << '\n';
}
ifile.close();
}
else cout << "Unable to open file";
return 0;
}