对C++十大容器中的结构体元素进行排序

#include <algorithm>

//比较函数
bool StructCmpFunc(const ReqWeatherParameter_t & strThis, const ReqWeatherParameter_t & strThat)
{
    QString qstrThis = strThis.wWeatherName.c_str();

    QString str3 = qstrThis.mid(qstrThis.lastIndexOf(':', -1) + 1);

    QString qstrThat = strThat.wWeatherName.c_str();

    QString str4 = qstrThat.mid(qstrThat.lastIndexOf(':', -1) + 1);

    return (str3.toInt() < str4.toInt());

}

    std::vector<ReqWeatherParameter_t> & vtWeatherParamData = stWeatherParameterData.vtWeatherParamData;

    sort(vtWeatherParamData.begin(), vtWeatherParamData.end(), StructCmpFunc); //排序

 

posted @ 2020-04-25 13:50  骄傲到自负  阅读(220)  评论(0)    收藏  举报