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; }