// TestVS2012.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <set>
#include <string>
struct Test
{
std::string name;
int age;
};
class CustomSort
{
public:
bool operator()(const Test &t1, const Test &t2) const
{
return t1.age < t2.age;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
std::set<Test, CustomSort> s;
Test t1;
t1.age = 2;
t1.name = "a";
Test t2;
t2.age = 1;
t2.name = "b";
s.insert(t1);
s.insert(t2);
getchar();
return 0;
}
C/C++--set排序
最新推荐文章于 2022-08-28 16:43:47 发布