与set容器相比允许重复键值的插入
#include<set>
#include<string>
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
///定义元素类型为string的多重集合对象s,当前没有任何元素
multiset<string> ms;
ms.insert("abc");
ms.insert("123");
ms.insert("111");
ms.insert("aaa");
ms.insert("123");
for(auto it = ms.begin();it != ms.end();it++)
cout << *it << endl;
printf("\n");
///multiset中元素的删除
///删除值为“123”的所有重复元素,返回删除总数为2
int n = ms.erase("123");
cout << "Total deleted:" << n << endl;
cout << "all element after deleted:" << endl;
for(auto it = ms.begin();it != ms.end();it++)
cout << *it << endl;
printf("\n");
///查找元素
ms.insert("123");
ms.insert("123");
///查找键值“123”
auto it = ms.find("123");
if(it != ms.end())
cout << *it << endl;
else
cout << "该元素不存在" << endl;
it = ms.find("ddd");
if(it != ms.end())
cout << *it << endl;
else
cout << "该元素不存在" << endl;
return 0;
}