essentially i have a function that writes a score to a text file, however i'm not sure how to write to a respective line in the text file based on the score so it writes to the bottom of the file on the next available line, and i also want a function to print the top 10 scores, however since that file is not sorted by score ( if there's an easy way to do that instead an answer for that is welcome ) my idea was to read all the lines in the file and put them into an array of strings, and then sort the array based on the numbers inside the array.
for example, the text file has the format of SCORE then NAME, here is an example of the file
1548 Bob Jones
604 James Jones
5516 Example Name
24 Bad Score ikr
to print this to the file i get input for the name from user, then i output to file with
HighScore << totalScore << " " << Name << std::endl;
i would like to be able to print the top 10 scores and the respective names of the player to the console, so the output would look something like this in the console
1) 5516 Example Name
2) 1548 Bob Jones
3) 604 James Jones
4) 24 Bad Score ikr
since my idea was to use arrays of strings, i still dont know how to sort it by the initial score numbers in the string, if there is a better solution to printing out the top 10 scores from a file then please let me know! thankyou