看看地图中是否有钥匙c
发布时间:2020-12-16 09:37:58 所属栏目:百科 来源:网络整理
导读:在我的函数中,我有这个参数: mapstring,int *itemList 我想先检查是否存在密钥.如果此键存在,则获取该值. 我想这个: mapstring,int::const_iterator it = itemList-find(buf.c_str());if(it!=itemList-end()) //how can I get the value corresponding to
在我的函数中,我有这个参数:
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? 检查密钥是否存在的正确方法是什么? 解决方法
是的,这是正确的方法.与键关联的值存储在std :: map iterator的第二个成员中.
map<string,int>::const_iterator it = itemList->find(buf.c_str()); if(it!=itemList->end()) { return it->second; // do something with value corresponding to the key } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |