map查找统计

#include <iostream>
#include <map>
using namespace std;

int main()
{
   map<int, string> m;
   m.insert(pair<int, string>(1, "furong"));
   m.insert(pair<int, string>(2, "quange"));
   m.insert(pair<int, string>(3, "zhangsan"));

   map<int, string>::iterator it = m.find(2);
   if(it != m.end())
   {
      cout << it->first << ": " << it->second << endl;
   }

   int count = m.count(2);
   cout << count << endl;

   return 0;
}
$ ./a.out     
2: quange
1
posted @ 2022-07-30 18:04  thomas_blog  阅读(17)  评论(0编辑  收藏  举报