Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote