C++map容器-查找和统计
生活随笔
收集整理的這篇文章主要介紹了
C++map容器-查找和统计
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
map查找和統計
功能描述:
對map容器進行查找數據以及統計數據
函數原型:
代碼如下:
#include <iostream> using namespace std; #include <map> //map容器 查找和統計void test01() {//查找map<int, int >m;m.insert(pair<int, int>(1, 10));m.insert(pair<int, int>(2, 20));m.insert(pair<int, int>(3, 30));m.insert(pair<int,int>(3,40));//map不允許插入重復key 元素map<int, int >::iterator pos = m.find(3);if (pos != m.end()) {cout << "查到了元素key = " << (*pos).first << " " << "value = " << pos->second << endl;} else {cout << "未找到元素" << endl;}//統計//map不允許插入重復key 元素,count統計而言,結果要么是0,要么是1//multimap的count統計可能大于1int num = m.count(3);cout << "num = " << num << endl;}int main() {test01();return 0; }總結
以上是生活随笔為你收集整理的C++map容器-查找和统计的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 苹果手机如何绑定邮箱
- 下一篇: 以隐身模式启动浏览器 不留一丝足迹