Highscore

I'm still new on C++ can anyone help me, I need the scores arrange themselves. For example I am the third player on the game and I rank the highscores, I want to be place at the first line and is there a way making it tabulated? Can anyone help me.
Create a class for a score if you haven't already and define operator< so that it always places you first, like you wanted.
Then you can use std::sort on your vector of scores and pick the top x from the vector.
As for making it tabulated: use tabs.
Can you make an example? pls
i should bulid a Sort
Example:Selection Sort or Quick Sort to Sort score you entered.
good luck.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
struct Score
{
  constructors
  [...]
  bool operator<(const Score& rhs) const {return (name=="It is I" && name!=rhs.name) || score>rhs.score;}

  std::string name;
  int score;
  DateTime date;
  [...]
};

vector<Score> scores;
sort(scores.begin,scores.end());
const int highScoreEntries=min(10u,scores.size());
for(i : 0..highScoreEntries-1)scores[i].print();
Last edited on
for(i : 0..highScoreEntries-1)scores[i].print();


Can I know you use which C++ compiler to be able to compile above for statement? :P
Im using devC++
Topic archived. No new replies allowed.