#include<map> map<int, int> mapCode; for (int i = 0; i < m_pDb->m_vResult.size(); i += 2) { mapCode.insert(std::pair<int, int>(m_pDb->m_vResult.at(i + 1).typeInt64, m_pDb->m_vResult.at(i).typeInt64)); }
Searches the container for elements with a key equivalent to k and returns the number of matches. Because all elements in a map container are unique, the function can only return1 (if the element is found) orzero (otherwise). if ( 0 < g_mapHookInfo.count(hWnd)) { //present HOOKINFO hookInfo = g_mapHookInfo[hWnd]; if (hookInfo.type == type) { return0; // already hooked! } }
赋值 [] insert 区别
insert 操作:如果key存在,则插入失败,如果key不存在,就创建这个key-value。实例: map.insert((key, value)) [] 操作符:如果这个key存在,就更新value;如果key不存在,就创建这个key-value对 实例:map[key] = value
// assume m is std::map<int,int> already has an element with key 5 and value 0 m[5] = 10; // postcondition: m[5] == 10 m.insert(std::make_pair(5,15)); // m[5] is still 10