【发布时间】:2011-12-13 02:32:13
【问题描述】:
在我的函数中,我有这个参数:
map<string,int> *&itemList
我想先检查一个键是否存在。如果此键存在,则获取该值。 我是这么想的:
map<string,int>::const_iterator it = itemList->find(buf.c_str());
if(it!=itemList->end())
//how can I get the value corresponding to the key?
是检查密钥是否存在的正确方法吗?
【问题讨论】:
-
@FailedDev 我不同意建议的重复项-该问题是关于搜索 values 但这个问题是关于搜索 keys (然后使用相应的值,但它们是非常不同的问题)