我首先定义了一个student类 内有整型学号 整型分分数等数据
然后我想使用
vector<student> stu
中的sort函数进行排序 排序的根据是分数对vector进行降序排序
但是当我写出
sort(stu.rbegin(),stu.rend())
编译报错了
所以该如何仅根据每个对象中的分数进行排序呢
下面是我的代码
#include <bits/stdc++.h>
using namespace std;
class student
{
public:
int no;
int score;
student(int No=0, int Score=0)
{
no = No;
score = Score;
}
};
int main()
{
int no;
int score;
vector<student> stu;
for (int i = 0; i < 3; i++)
{
cin >> no;
cin >> score;
student temp(no,score);
stu.push_back(temp);
}
sort(stu.rbegin(),stu.rend());
}