How do i get my program to read the last ten lines of the ".txt" file?
Can you please dumb it down as much as possible.
Here is what i have so far:
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string line;
ifstream myfile ("test.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
/*
An output example:
25: this is line 25
26: this is line 26
27: this is line 27
28: this is line 28
29: this is line 29
30: this is line 30
31: this is line 31
32: this is line 32
33: this is line 33
34: this is line 34
assuming the .txt file only had 34 lines
*/