/*copyright(c)2016.烟台大学计算机学院
* All rights reserved,
* 文件名称:text.Cpp
* 作者:刘涛
* 完成日期:2016年6月6日
* 版本号:vc++6.0
* 问题描述:阅读程序
*/
#include <algorithm>
#include<set>
#include<iterator>
#include<iostream>
using namespace std;
int main()
{
multiset<int>eg1;
//插入
eg1.insert(1);
eg1.insert(100);
eg1.insert(5);
eg1.insert(1);//是否插入
eg1.insert(10);
eg1.insert(9);
//遍历set,可以发现元素是有序的
multiset<int>::iterator set_iter=eg1.begin();
cout<<"Set named eg1:"<<endl;
for(; set_iter!=eg1.end(); set_iter++)
cout<<*set_iter<<" ";
cout<<endl;
//使用size()函数可以获得当前元素个数
cout<<"Now there are "<<eg1.size()<<" elements in the set eg1"<<endl;
if(eg1.find(200)==eg1.end())//find()函数可以查找元素是否存在
cout<<"200 isn't in the set eg1"<<endl;
return 0;
}
运行结果:
多重映射与映射唯一的区别就是多重映射可以一对多,可以有重复的元素。