How would i read the last 10 lines from a file using the code ive done so far? #
ID: 3543941 • Letter: H
Question
How would i read the last 10 lines from a file using the code ive done so far?
#include <iostream>
#include<string>
#include<fstream>
using namespace std;
//Main execution begins here
int main()
{
//Declare the variables
string fileName;
string line;
cout<<"Enter a file to read"<<endl;
//Input the filename
cin>>fileName;
fstream inFile;
//reading from a file
inFile.open(fileName, ios::in);
int count = 0;
?
while (!inFile.eof()){
while(getline(inFile,line))
{
cout << line << endl;
count++;
}
}
inFile.close();
cout << count;
?
system("PAUSE");
}
?
Explanation / Answer
UPD 1:
changed code: it has just 1 error now - if input has lines like
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.