C++ set增删改查遍历
int main() { set<int> test; //插入 test.insert(2); test.insert(1); test.insert(4); test.insert(5); test.insert(3); //遍历 for (auto i : test) cout << i << endl; cout << endl; auto iter = test.rbegin();//最大的N个数 for (int i = 0; i < 3;i++) cout << *iter++ << endl;//双向迭代器不支持随机访问 //删除 test.erase(4);//特定元素 auto it = test.begin();//最小的N个数 for (int i = 0; i < 2;i++) it=test.erase(it); //查找 if (test.find(5) != test.end()) cout << "find it" << endl; return 0; }