【发布时间】:2009-11-11 19:55:42
【问题描述】:
如何按姓名、年龄和分数对以下代码进行排序...所有三个字段
#include <string>
#include <vector>
#include <algorithm>
struct student_t
{
std::string name;
int age, score;
};
bool by_more_than_1_field( student_t const &lhs, student_t const &rhs )
{
// sort by name, age and score
}
int main()
{
std::vector< student_t > students;
// populate students
std::sort( students.begin(), students.end(), by_more_than_1_field );
}
【问题讨论】:
标签: c++ vector sorting compare