C++ 如何使用多数据对向量进行排序?

C++ 如何使用多数据对向量进行排序?,c++,algorithm,sorting,vector,C++,Algorithm,Sorting,Vector,我有这样一个向量: struct StatFaces { std::string faceName_1; std::string faceName_2; float percentagePerson ; }; std::vector<StatFaces> listFaces_; 排序算法必须将firstName_1分组,然后根据percentagePerson进行排序 PS:我不擅长C++ +P>> P>你可以将自定义的比较函数传递给 STD::排序<

我有这样一个向量:

struct StatFaces
{
    std::string faceName_1;
    std::string faceName_2;
    float percentagePerson ;
};

std::vector<StatFaces> listFaces_;
排序算法必须将firstName_1分组,然后根据percentagePerson进行排序


PS:我不擅长C++ +P>> P>你可以将自定义的比较函数传递给<代码> STD::排序< /COD>。这可以通过使用

std::tie
实现:

#include <tuple> // for std::tie

bool cmp(const StatFaces& lhs, const StatFaces& rhs)
{
  return std::tie(lhs.face_name1, lhs.percentagePerson, lhs.faceName_2) <
         std::tie(rhs.face_name1, rhs.percentagePerson, rhs.faceName_2);
}
#包括//用于std::tie
bool cmp(恒站面和左侧、恒站面和右侧)
{
返回std::tie(lhs.face_名称1、lhs.percentagePerson、lhs.face名称_2)<
标准::tie(rhs.face_Name 1、rhs.percentagePerson、rhs.face Name_2);
}
然后

#include//for std::sort
std::sort(listFaces_u2;.begin()、listFaces_2;.end()、cmp);

<代码> STD::TIG/<代码>返回一个LUP值引用的参数,并且有一个字典比比较少<代码> BoOL操作程序抱歉,请您解释我更多,因为我不太熟悉C++。
#include <tuple> // for std::tie

bool cmp(const StatFaces& lhs, const StatFaces& rhs)
{
  return std::tie(lhs.face_name1, lhs.percentagePerson, lhs.faceName_2) <
         std::tie(rhs.face_name1, rhs.percentagePerson, rhs.faceName_2);
}
#include <algorithm> // for std::sort

std::sort(listFaces_.begin(), listFaces_.end(), cmp);