用sort如何对一个二维数组排序,数组元素都是结构体;
我想要实现records的第二维数据按照time进行排序,如何书写sort的第三个参数
struct month
{
string time;
string status;
};
struct customer
{
double total_amount;
vector<vector<month>> records;
};
bool cmp(const month &a, const month &b)
{
if (a.time < b.time)
return 1;
return 0;
}
customer data[100];
sort(data[0].records[0].begin(),data[0].records[0].end(),cmp);
// 结果显示data[0].records[0]这个数组的元素没有按照time从小到大排序
如果我用以下代码则可以实现
vector<month>temp = data[0].records[0];
sort(temp.begin(),temp.end(),cmp);
data[0].records[0] = temp;
这是为啥=-=