判断某key是否存在可以使用map的count方法来间接判定
count接受一个参数key值,返回map中key值为给定值的元素总数
1 map<int, string> i_to_s_map; 2 int mount = i_to_s_map.count(100);
如果mount=0,则map中不存在key值为100的元素,反之则存在
判断某key是否存在可以使用map的count方法来间接判定
count接受一个参数key值,返回map中key值为给定值的元素总数
1 map<int, string> i_to_s_map; 2 int mount = i_to_s_map.count(100);
如果mount=0,则map中不存在key值为100的元素,反之则存在
转载于:https://www.cnblogs.com/zhuangbijingdeboke/p/9089184.html