I have a .txt file which I want to read from and then write a new text file, this time with sorted lines. It is easy to sort one value, but what about sorting entire lines based on one value?
I want to sort the lines based on the FIRST value.
If this is a unix system, just do sort -n < file.txt
If you have to write the code, then you need a class with two members: the number and the string. Add operator < that works on the number. Now read the files, populate an instance of your class and drop it into a std::set. When you're done, just iterate over the set and write them out. This will work because sets are ordered.