Write a program that asks the user for the name of a file. The program should display the last 10 lines of the file on the screen (the "tail" of the file). If the file has fewer than 10 lines, the entire file should be displayed, with a message indicating the entire file has been displayed.
The above is a homework assignment that I have to complete.
I have successfully achieved getting an output of all the data. However, I cannot figure out how to only print the last 10 lines of data. I believe that passing everything into a string array is the solution. This way I can just limit which lines are printed out. The only problem is that I cannot figure out how to do this. I have tried everything that I can think of and I get the program to without any errors but there is no output. Please help.
One way is to count the lines in the file first. The second time you skip all but the last 10 lines and display the rest.
Of course the easiest way would be to read all the lines into a vector, but I am not sure if you are allowed to use vectors.