学习multiset多重集合容器

 1 # include<set>
 2 # include<cstdio>
 3 # include<iostream>
 4 using namespace std;
 5 int main(int argc,const char *argv[])
 6 {
 7     /*-------------------------------------------*/
 8     //multiset中插入数据
 9     //multiset<string>ms;
10     //ms.insert("abc");
11     // ms.insert("123");
12     //ms.insert("111");
13     //ms.insert("aaa");
14     //ms.insert("123");
15     //multiset<string>::iterator it;
16     //for(it = ms.begin();it!=ms.end();it++)
17     //{
18     //    cout<<*it<<endl;
19     //}
20 
21     /*--------------------------------------------*/
22     //multiset元素的删除
23     //multiset<string>ms;
24     //ms.insert("abc");
25     //ms.insert("123");
26     //ms.insert("111");
27     //ms.insert("aaa");
28     //ms.insert("123");
29     // multiset<string>::iterator it;
30     //for(it = ms.begin(); it!=ms.end(); it++)
31     //{
32     //     cout<<*it<<endl;
33     // }
34     //int n = ms.erase("123");
35     //cout<<"Total deleted:"<<n<<endl;
36 
37     //cout<<"all elements after deleted"<<endl;
38     //for(it = ms.begin(); it!=ms.end(); it++)
39     //{
40     //    cout<<*it<<endl;
41     //}
42 
43     /*-----------------------------------*/
44     //查找元素
45     multiset<string>ms;
46     ms.insert("abc");
47     ms.insert("123");
48     ms.insert("111");
49     ms.insert("aaa");
50     ms.insert("123");
51     multiset<string>::iterator it;
52     it = ms.find("123");
53    if(it!=ms.end())
54     {
55         cout<<*it<<endl;
56     }
57     else
58     {
59         cout<<"not find it"<<endl;
60     }
61     it = ms.find("bbb");
62     if(it!= ms.end())
63     {
64         cout<<*it<<endl;
65     }
66     else
67     {
68         cout<<"not find it"<<endl;
69     }
70 
71 
72 }
View Code
原文地址:https://www.cnblogs.com/sxmcACM/p/3460196.html