STL Set(2)

View Code
 1 #include <iostream>
2 #include<set>
3
4 using namespace std;
5 typedef multiset<int> MSETINT;//set插入比vector稍慢 他不是顺序容器 不能再找到数据后直接修改,需删除后再添加新数据。
6 int main()
7 {
8
9 MSETINT a;
10
11 a.insert(43);
12 a.insert(78);
13 a.insert(78);
14 a.insert(-1);
15 a.insert(124);
16
17
18 MSETINT::const_iterator i;
19 cout << "multiset里有" << a.size() << "个数据"<< endl;
20
21 cout<< "显示所有的数据: "<< endl;
22
23 for (i = a.begin(); i!=a.end(); ++i)
24 cout << *i << endl;
25
26
27 cout << "要删除的数据: "<< endl;
28 int nNumberToErase = 0;
29 cin >> nNumberToErase;
30
31 a.erase(nNumberToErase);
32
33 cout<< "删除以后显示所有的数据: "<< endl;
34
35 for (i = a.begin(); i!=a.end(); ++i)
36 cout << *i << endl;
37
38
39 a.clear();//全部清空
40
41 return 0;
42 }
posted @ 2012-03-27 23:29  uniquews  阅读(122)  评论(0编辑  收藏  举报