Arrays have only members of the same datatype, you can't mix strings and numbers.
You can define a structure
- Code: Select all
struct foo
{
string name;
int score;
};
and define an array of this structure. Then you can sort the array. You have to define a compare operator or a compare function or a functor class.
- Code: Select all
bool operator<(foo &a, foo &b)
{
return a.score < b.score;
}
If you use std::vector instead of an array the sorting is as easy as
- Code: Select all
std::vector<foo> foovector;
// put some elements in the vector
std::sort(foovector.begin(), foovector.end());
Who needs a signature anyway.