判断Key值是否存在 C++
- 通过map的count接口函数来判断
if(myMap.conunt(iKey) == 1)
{
//说明IKey存在于myMap;
}
else
{
//myMap.conunt(iKey) == 0;
//说明IKey不存在于myMap;
}
- 通过map的find接口函数来判断
if(myMap.find(iKey) != myMap.end())
{
//说明IKey存在于myMap;
}
else
{
//myMap.find(iKey) == myMap.end();
//说明IKey不存在于myMap;
}
我个人觉得这个是两种比较好的方法,更推荐第一种。