#include#include using namespace std; int main() { set s; s.insert(10); s.insert(20); s.insert(30); s.insert(20); // won't be inserted again for(auto it=s.begin(); it!=s.end(); ++it) cout << *it << " "; // output: 10 20 30 return 0; }
#includePackage library: STL (Standard Template Library)#include using namespace std; int main() { set s; auto res = s.insert(10); if (res.second) cout << "10 was inserted" << endl; res = s.insert(20); if (res.second) cout << "20 was inserted" << endl; res = s.insert(10); if (!res.second) cout << "10 was not inserted (already exists)" << endl; return 0; }