Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ std::vector Struct学生示例 #包括 #包括 #包括 #包括 struct StudentDataTypes { std::字符串名{}; int级{}; }; int main() { //询问班级大小 int Class_Size{}; 标准::cout Class_尺寸; //语法格式 //std::向量数组(大小); //初始化名为vector_Student的学生向量 //T指向struct StudentDataTypes的链接 //大小是班级的大小。 std::矢量学生(班级规模); //打印班级人数 std::cout_C++_Sorting_Std_Stdvector - Fatal编程技术网

C++ std::vector Struct学生示例 #包括 #包括 #包括 #包括 struct StudentDataTypes { std::字符串名{}; int级{}; }; int main() { //询问班级大小 int Class_Size{}; 标准::cout Class_尺寸; //语法格式 //std::向量数组(大小); //初始化名为vector_Student的学生向量 //T指向struct StudentDataTypes的链接 //大小是班级的大小。 std::矢量学生(班级规模); //打印班级人数 std::cout

C++ std::vector Struct学生示例 #包括 #包括 #包括 #包括 struct StudentDataTypes { std::字符串名{}; int级{}; }; int main() { //询问班级大小 int Class_Size{}; 标准::cout Class_尺寸; //语法格式 //std::向量数组(大小); //初始化名为vector_Student的学生向量 //T指向struct StudentDataTypes的链接 //大小是班级的大小。 std::矢量学生(班级规模); //打印班级人数 std::cout,c++,sorting,std,stdvector,C++,Sorting,Std,Stdvector,std::sort要求您实现操作符以下是答案。我将在答案中发布如何对向量结构进行排序 步骤1: std::sort(Vector_Student.begin(), Vector_Student.end(), [](const StudentDataTypes& a, const StudentDataTypes&b) { return a.grade < b.grade; }); 步骤2: bool compareTwoStudents(StudentDataTypes

std::sort
要求您实现
操作符以下是答案。我将在答案中发布如何对向量结构进行排序

步骤1:

std::sort(Vector_Student.begin(), Vector_Student.end(), [](const StudentDataTypes& a, const StudentDataTypes&b) { return a.grade < b.grade; });
步骤2:

bool compareTwoStudents(StudentDataTypes a, StudentDataTypes b) {
    if (a.grade != b.grade)
        return a.grade > b.grade;
    return a.grade==b.grade;
} 

代码“sort of”是如何编译的?(它不为我编译,这意味着它不是为你的崩溃而编译的。)这不可编译。要进行排序,你需要一个比较函数或
,你能做一个
重建
(不运行
运行
)并显示输出吗?我很好奇你如何编译
std::sort()
如果
StudentDataTypes
未提供比较运算符,则调用…@JonhSmithBenjamin不在问题中写入答案。在答案中写入答案。您还可以提供排序比较参数,不必是类的一部分。
std::sort(Vector_Student.begin(), Vector_Student.end(), [](const StudentDataTypes& a, const StudentDataTypes&b) { return a.grade < b.grade; });
bool compareTwoStudents(StudentDataTypes a, StudentDataTypes b) {
    if (a.grade != b.grade)
        return a.grade > b.grade;
    return a.grade==b.grade;
} 
std::sort(Vector_Student.begin(), Vector_Student.end(),compareTwoStudents);