Make an array of 10 strings.
Put each line read into this array.
After you've read 10 lines, start overwriting the strings from string[0].
In other words:
read line 1 --> load string[0]
read line 2 --> load string[1]
read line 3 --> load string[2]
read line 4 --> load string[3]
read line 5 --> load string[4]
read line 6 --> load string[5]
read line 7 --> load string[6]
read line 8 --> load string[7]
read line 9 --> load string[8]
read line 10 --> load string[9]
read line 11 --> load string[0]
read line 12 --> load string[1]
etc...
To output, skip to the next string (the one after the last one written) and start writing all the strings in order.
But -- what happens if there are only 7 lines in the file? Yours to figure out.
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
As Schoil-R-LEA mentioned above correctly, you need an input file stream to read from a file. ofstream is used for output. Also note that your second while loop will never print anything if your file contains less than 10 lines. The structure of the programm should rather be modified.
Y.G. Tha s egrafa sta ellinika alla exoun kanona... :) an xreiasteis kati allo steile minima
mikrosfoititis
Junior Poster in Training
74 posts since Nov 2011
Reputation Points: 18
Solved Threads: 11
I'll try what WaltP said.. but I'll have to use dynamic memory in that case and we just mentioned a few things about pointers in class.
Why? Your analysis is faulty.
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944