当前位置:网站首页>STL multimap
STL multimap
2022-07-24 03:23:00 【joker_0030】
#include <iostream>
#include <map>
//#include <algorithm>
using namespace std;
int main()
{
multimap<int, char> db;
db.insert(pair<int, char>(1, 'd'));
db.insert(pair<int, char>(1, 'e'));
db.insert(pair<int, char>(2, 'd'));
db.insert(pair<int, char>(1, 'f'));
db.insert(pair<int, char>(3, 'd'));
//返回multimap键值的数量,无则返回0。
cout << db.count(1) << endl;
//迭代输出
multimap<int, char>::iterator ite = db.begin();
for (ite; ite != db.end(); ite++)
{
cout<<ite->first<<" "<<ite->second<<endl;
}
//查找:
map<int, char>::iterator ite1 = db.find(1);//查找2这个键值,查找到会返回第一个1所在位置的迭代器。
if (db.end() == db.find(6)) //如果容器中没有6这个键值,则find返回最后一个元素end()(并不是最后一个键值,而是实际尾元素的下一个end()),运行会崩溃。
{
cout << "OK" << endl;
}
cout << ite1->first << " " << ite1->second << endl;
system("pause");
return 0;
}
*1、操作函数与map都一样
2、与map函数的区别:a、允许键值重复。
b、计数。count。
c、find函数返回第一个匹配的函数,没找到返回最后一个。
边栏推荐
- Tweenmax+svg Pikachu transformation ball
- Correct usage of iota in golang
- leetcode hot 100(刷题篇8)(232/88/451/offer10/offer22/344/)
- 如何在 pyqt 中实现桌面歌词
- Test interview questions
- kettle
- FTP service and configuration
- How to write selenium's testng.xml
- 【无标题】
- Svn: e00002: can't convert string from 'UTF-8' to native encoding problem solving
猜你喜欢

拉格朗日插值法

Internet of things installation and debugging personnel let "smart" life come early

How to realize software function safety

MySQL learning - MySQL software installation and environment configuration (Windows) details!

OSPF comprehensive experimental configuration

JS small game running bear and cat source code

Gpushare.com | 如何使用TensorBoardX可视化工具?

IO stream sorting

The new idea 2022.2 was officially released, and the new features are nice

SolidWorks CAM data cannot be recovered because a processed part has been detected.
随机推荐
C. Minimum Ties-Educational Codeforces Round 104 (Rated for Div. 2)
Ue5 split screen (small map) solution
JS 数组 isAarray() typeof
[AMC] federal quantification
Bingbing learning notes: basic operation of vim tool
错误代码0x80004005
Okaleido tiger NFT is about to log in to the binance NFT platform. Are you looking forward to it?
Xiaodi and Xiaohui
322. Change
C dynamic memory management details
String.split() the most detailed source code interpretation and precautions
LCD1602 - binge 51
正則錶達式 \b \B 深入淺出理解單詞邊界的匹配
leetcode hot 100(刷題篇8)(232/88/451/offer10/offer22/344/)
What is the security of Treasury reverse repo
How to implement desktop lyrics in pyqt
Secondary development of ArcGIS JS API -- loading national sky map
JMeter interview script
Do the right thing, do it right
MariaDB related instructions