在我的功能的關鍵,我有這個參數:看看是否有在地圖C++
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?
是檢查按鍵是否存在正確的方法是什麼?
的可能重複:http://stackoverflow.com/questions/535317/checking-value-exist-in-a-stdmap-c – FailedDev
@FailedDev我所提出的重複不同意 - 這個問題是問搜索*值*但這個問題是關於搜索*鍵*(然後使用相應的值,但他們是非常不同的問題) – Flexo