【发布时间】:2016-09-15 05:02:01
【问题描述】:
我正在尝试访问特定哈希键的值。示例代码如下。 Test Here
// unordered_map::at
#include <iostream>
#include <string>
#include <unordered_map>
int main ()
{
std::unordered_map<std::string,int> hashmap = {
{ "Apple", 300},
{ "Banana", 60},
{ "Orange", 70 } };
std::cout << "Value :" << hashmap[300]<<std::endl;
return 0;
}
但是,当我尝试访问特定值的密钥时,它可以正常工作,例如 hashmap["Apple"],它提供 300,即 Apple 的密钥。如何让它像hashmap[300]一样工作,给“Apple”。
【问题讨论】:
-
相关/可能是骗子:stackoverflow.com/questions/535317/…