Reading Lines From a File
Here is the prob, i have a .txt file containing the following lines there are currently 5 lines but it can keep growing and growing in size.
I want to be able to read the last 5 lines from the file and display them to the screen. I also want to be able to display any one given line from the file and display it to the screen. For example the 3rd line if requested would display + 123 1579 Tue Feb 22 05:24:47 2005.
New lines are appended to the end of the file and the cursor is then placed on a new line awaiting further input.
+ 1000 1000 Tue Feb 22 04:33:57 2005
+ 456 1456 Tue Feb 22 05:24:44 2005
+ 123 1579 Tue Feb 22 05:24:47 2005
+ 1000 2579 Tue Feb 22 05:24:50 2005
- 123 2456 Tue Feb 22 05:24:53 2005
I can get the first line to display using:
And i can get it yo output the entire file using:
cout << line;
Its just the getline function thats confusing me really i think, a few tips on using it would be very helpfull.
while (getline(in, line) )
cout << line << endl;