I want to be able to read from an unsorted source text file (a record in each line), and insert the line/record into a destination text file by specifying the line number where it should be inserted. It will be determined where to insert the line/record into the destination file by comparing the incoming line from the source file to the already ordered list in the destination file. (the destination file will start as empty and be inserted/sorted a line at a time from iterating over the source file lines).
Incoming File Example:
1 10/01/2008 line1data
2 11/01/2008 line2data
3 10/15/2008 line3data
Desired Destination File Example:
2 11/01/2008 line2data
3 10/15/2008 line3data
1 10/01/2008 line1data
I could do this by performing the sort in memory via a linked list or similar, but I want to allow this to scale to very large files (and am having fun trying to solve this problem as a I am a C++ newbie :)
One of the ways to do this may be to open 2 file streams with fstream (1 in and 1 out, or just 1 in/out stream), but then I run into the difficulty that it's difficult find and search the file position because it seems to depend on absolute position from the start of the file rather than line numbers :)
I'm sure problems like this have been tackled before, and I would appreciate advice on how to proceed in a manner that is good practice.
I'm using Visual Studio 2008 Pro C++, and I'm just learning C++.
Thanks!!!