#include <iostream>
#include <set>
using namespace std;
template<typename Container>
void PrintContents(const Container& con);
template<typename Container>
void PrintContents(const Container& con)
{
Container::const_iterator iter = con.begin();
while (iter != con.end())
{
cout << *iter << " ";
++iter;
}
cout << endl;
}
int main()
{
set<int> set1;
multiset<int> multiset1;
set1.insert(10);
set1.insert(20);
set1.insert(30);
set1.insert(20);
cout << "size:" << set1.size() << endl;
set<int>::const_iterator set_iter1 = set1.begin();
while (set_iter1 != set1.end())
{
cout << *set_iter1 << " ";
set_iter1++;
}
cout << endl;
multiset1.insert(set1.begin(),set1.end());
multiset1.insert(50);
multiset1.insert(50);
cout << "--------------------------------------------" << endl;
cout << "multiset size:" << multiset1.size() << " " << multiset1.count(50) << endl;
multiset<int>::const_iterator multiset_iter1 = multiset1.begin();
while (multiset_iter1 != multiset1.end())
{
cout << *multiset_iter1 << " ";
multiset_iter1++;
}
cout << endl;
cout << "------------------------------------------- - " << endl;
PrintContents(multiset1);
cout << "------------------------------------------- - " << endl;
set<int>::iterator iter_f = set1.find(20);
if (iter_f != set1.end())
{
cout << "find: "<<*iter_f << endl;
}
else
{
cout << "not find:" << endl;
}
multiset1.erase(50);
PrintContents(multiset1);
system("pause");
return 0;
}
=======================================================
size:3
10 20 30
--------------------------------------------
multiset size:5 2
10 20 30 50 50
------------------------------------------- -
10 20 30 50 50
------------------------------------------- -
find: 20
10 20 30
请按任意键继续. . .