I am making project(game) in c++. i want to store score and display in such a way that the score will be displayed of 5 players who had high score. if new player makes high score then the player with lower score is deleted and new player with high score is edited.
so i want little idea how do i do it. i know how to insert and delete record in data file handling but i dont know how do i merge it..
and creating file in textmode is better or binary mode is better.
Then you make an array of myStruct and feed it into the std::sort algorithm:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
MyStruct ListOfPlayers[20];
ifstream fin("Players.txt");
// read in the data
for (int i = 0; !fin.eof() ; ++i)
{
fin >> ListOfPlayers[i].player;
fin >> ListOfPlayers[i].score;
}
// sort the data
std::sort(ListOfPlayers, ListOfPlayers+20, ListOfPlayers[0]);
// store
//...
This is what i did i dont know where do i do changes for
I am making project (game) in which score is stored. I want to write in a file in such way that it writes only scores of 5 persons. i.e
if score is higher then all other then it should be written at top and if lowest then end of file.
or
if score is between 1-5 then it should resemble lower score and delete the other which is lower then above.
for example, score stored in file is like this :
1. 5000
2. 4500
3. 4000
4. 3500
5. 3000
after playing game it should write like this if score is = 3800
1. 5000
2. 4500
3. 4000
4. 3800
5. 3500