set用法:
#include <set>
class Test {
public:
Test(int a,int b) {
this->a = a;
this->b = b;
}
bool operator < (const Test &t)const {
return b < t.b;
}
int a;
int b;
};
void test_set_compare() {
std::set<Test> test;
test.insert(Test(3,2));
test.insert(Test(5,5));
test.insert(Test(1,9));
test.insert(Test(6,1));
std::set<Test>::const_iterator iter_test;
for (iter_test = test.begin(); iter_test != test.end(); ++iter_test) {
std::cout << iter_test->a << "," << iter_test->b << std::endl;
}
}
int main() {
test_set_compare();
return 0;
}