您的位置:首页 > 其它

stl 学习笔记

2014-12-01 00:00 423 查看

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iterator