multimap和set的应用

/*
对于multimap的使用只需要包含map的头文件即可
*/
#include<iostream>
#include<set>
#include<string>
#include<map>
using namespace std;
int main()
{
	set<string>a;
	a.insert("aef");
	a.insert("efe");
	set<string>::iterator it=a.find("aef");
	cout<<*it<<endl;
	multimap<string,string>authors;
	authors.insert(make_pair(("ffe"),("feg")));
	authors.insert(make_pair(("ffe"),("dfl")));
	authors.insert(make_pair(("ffe"),("dfe")));
         authors.insert(make_pair(("ffe"),("dfe")));
         //multimap中允许插入键——值相同的元素,且不会覆盖,这相同的两个元素
         //都可以输出。
	typedef multimap<string,string>::iterator ite;
	ite beg,end;
	beg=authors.lower_bound("ffe");
	end=authors.upper_bound("ffe");
	while(beg!=end)
	{
		cout<<beg->second<<endl;
		++beg;
	}
	pair<ite,ite>pos=authors.equal_range("ffe");
	while(pos.first!=pos.second)
	{
		cout<<pos.first->second<<endl;
		++pos.first;
	}
	return 0;
}

最后面的两个循环是使用两种方法实现了multimap 中元素的查找。

你可能感兴趣的:(String,iterator,pair)