1、count函数

count函数用于统计key值在map中出现的次数,map的key不允许重复,因此如果key存在返回1,不存在返回0

if (testMap.count(key) == 0)
    cout << "no this key" << endl;

2、find函数

iterator find ( const key_type& key );

如果key存在,则find返回key对应的迭代器,如果key不存在,则find返回尾后迭代器 .end()
例:

if (testMap.find(key) == testMap.end())
    cout << "no this key" << endl;

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-18
  • 2022-12-23
  • 2021-11-28
  • 2021-11-04
相关资源
相似解决方案