在C++中的多重映射看起來工作非常奇怪的,我想知道爲什麼unordered_multimap - 迭代的find()的結果產生不同的價值元素
#include <iostream>
#include <unordered_map>
using namespace std;
typedef unordered_multimap<char,int> MyMap;
int main(int argc, char **argv)
{
MyMap map;
map.insert(MyMap::value_type('a', 1));
map.insert(MyMap::value_type('b', 2));
map.insert(MyMap::value_type('c', 3));
map.insert(MyMap::value_type('d', 4));
map.insert(MyMap::value_type('a', 7));
map.insert(MyMap::value_type('b', 18));
for(auto it = map.begin(); it != map.end(); it++) {
cout << it->first << '\t';
cout << it->second << endl;
}
cout << "all values to a" << endl;
for(auto it = map.find('a'); it != map.end(); it++) {
cout << it->first << '\t' << it->second << endl;
}
}
這是輸出:
c 3
d 4
a 1
a 7
b 2
b 18
all values to a
a 1
a 7
b 2
b 18
爲什麼輸出仍然包含任何與b作爲關鍵時,我明確要求'一個'?這是一個編譯器或STL錯誤?
如果更改 - >到。那麼我會接受你的答案。 – Arne 2012-01-28 16:58:41
我有' - >'快樂。 – user7116 2012-01-28 17:04:05