#include <iostream> #include <set> using namespace std; int main() { set<int>set1; for(int i=9; i>0; i--) set1.insert(i); //有序插入 set1.erase(3); for(set<int>::iterator p=set1.begin(); p!=set1.end(); ++p) cout<<*p<<""; cout<<endl; if(set1.insert(3).second) //把3插入到set1中 //插入成功则set1.insert(3).second返回1,否则返回0 //此例中,set不能插入重复元素集中已经有3这个元素了,所以插入将失败 cout<<"set insert success"; else cout<<"set insert failed"; cout<<endl; for(set<int>::iterator p=set1.begin(); p!=set1.end(); ++p) cout<<*p<<""; cout<<endl; int a[] = {4, 1, 1, 1, 1, 1, 0, 5, 1, 0}; multiset<int> A; A.insert(set1.begin(),set1.end()); for(set<int>::iterator p=A.begin(); p!=A.end(); ++p) cout<<*p<<""; cout<<endl; A.insert(a,a+10); for(set<int>::iterator p=A.begin(); p!=A.end(); ++p) cout<<*p<<""; cout<<endl; return 0; }