- 【1】本博客主要讲解了set的几种赋值方法
- 【2】一些常用的操作count、equal_range等
- -
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
int main()
{
int a[] = {5,3,9,3,7,2,9,3};
multiset<int>myset,myset1;
vector<int>iVec(a,a+sizeof(a)/sizeof(int));
for(int i = 0; i < sizeof(a)/sizeof(a[0]);i++)
{
myset.insert(a[i]);
}
for(multiset<int>::iterator it = myset.begin();it != myset.end();it++)
{
cout<<*it<<" ";
}
cout<<endl;
myset1.insert(myset1.end(),1);
myset1.insert(myset1.begin(),1);
for(multiset<int>::iterator it = myset1.begin();it != myset1.end();it++)
{
cout<<*it<<" ";
}
cout<<endl;
multiset<int>myset2(myset.begin(),myset.end());
for(multiset<int>::iterator it = myset2.begin();it != myset2.end();it++)
{
cout<<*it<<" ";
}
cout<<endl;
set<int>myset4(a,a+sizeof(a)/sizeof(int));
set<int>myset5(a,a+2);
myset5.swap(myset4);
copy(myset4.begin(),myset4.end(),ostream_iterator<int>(cout," "));
cout<<endl;
copy(myset5.begin(),myset5.end(),ostream_iterator<int>(cout," "));
cout<<endl;
int icount = myset4.count(3);
int icount2 = myset2.count(3);
pair<set<int>::iterator,set<int>::iterator>rangeset;
pair<multiset<int>::iterator,multiset<int>::iterator>rangemultiset;
rangeset = myset4.equal_range(3);
rangemultiset = myset.equal_range(3);
for(set<int>::iterator it = rangeset.first;it != rangeset.second;it++)
{
cout<<*it<<endl;
}
system("pause");
return 0;
}