#include <iostream>
#include <set>
using namespace std;
int main() {
set<int> tmp;
set<int>::iterator i;
tmp.insert(3);
tmp.insert(2); //插入
tmp.insert(1);
tmp.insert(3);
for(i = tmp.begin(); i != tmp.end(); i++)
cout << *i << endl; //遍历,可以看出set自动排序好了
tmp.erase(2); //删除
for(i = tmp.begin(); i != tmp.end(); i++)
cout << *i << endl;
for(i = tmp.begin(); i != tmp.end(); i++)
tmp.erase(i); //删除全部
cout << tmp.size() << endl; //size为0
}
stl set 的用法
最新推荐文章于 2022-01-18 09:28:57 发布