直接贴代码
#include <hash_map>
#include <string>
#include <iostream>
using namespace stdext;
using namespace std;
int main()
{
hash_multimap<int, string> hm1;
hm1.insert(pair<int, string>(1, "hello"));
hm1.insert(pair<int, string>(1, "hellos"));
hm1.insert(pair<int, string>(2, "hello"));
hm1.insert(pair<int, string>(2, "hellos"));
hash_multimap<int, string>::const_iterator moveIterator = hm1.lower_bound(1);
hash_multimap<int, string>::const_iterator endIterator = hm1.upper_bound(1);
for (; moveIterator != endIterator; ++moveIterator)
{
cout << moveIterator->second << endl;
}
return 0;
}
具体实现就是用到了两个迭代器lower_bound upper_bound