#include<iostream>
using namespace std;
#include<map>
int main(void) {
multimap<string, string> city = { {"中国","上海" },
{"美国","华盛顿"},
{"中国","北京" },
{"日本","东京" },
{"中国","广州" },
{"美国","纽约" }
};
/*
* 返回一个迭代器pair,表示关键字等于key的元素的范围。
* 若key不存在,pair的两个成员均等于end()
*/
auto pair = city.equal_range("中国");
if (pair.first == city.end() && pair.second == city.end()) //pair.first == pair.second
cout << "没找到!" << endl;
else
while (pair.first != pair.second) {
cout << pair.first->first << " : " << pair.first->second << endl;
++pair.first;
}
system("pause");
return 0;
}
equal_range在map中的使用
最新推荐文章于 2023-05-24 11:46:16 发布