Here's the problem I'm working on: Write a program that asks the user for the name of a text file. The program should display the last 5 lines of the file on the screen. If the file has fewer than 5 lines, the entire file is displayed, with a message that the entire file has been displayed. The program should do this by seeking to the end of the file and then backing up to the fifth line from the end of file.
I've managed to get to the end of the file using
inFile.seekg(0, ios::end);
but I'm stumped as to how I can back up five lines from there. The lines of text vary in size.
OK, let me try to narrow down the help I need with this: Is there a way to search backwards (starting from the end) through a text file for a new line character, and if so, how do you do that?