当前位置:网站首页>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函数返回第一个匹配的函数,没找到返回最后一个。
边栏推荐
- JS Array isaarray () Type of
- The next stop of data visualization platform | gifts from domestic open source data visualization datart "super iron powder"
- FTP服务与配置
- Industrial controller, do you really know your five insurances and one fund?
- 数据湖:开源数据湖方案DeltaLake、Hudi、Iceberg对比分析
- What is the experience of writing concurrent tool classes (semaphore, cyclicbarrier, countdownlatch) by yourself in line 30?
- Basic syntax of MySQL DDL and DML and DQL
- C. Minimum Ties-Educational Codeforces Round 104 (Rated for Div. 2)
- Write code, and multiple characters move from both ends to converge in the middle
- Ue5 split screen (small map) solution
猜你喜欢

MySql的DDL和DML和DQL的基本语法

C file operation details

An introductory example of structure and combinatorial ideas in go language

Error code 0x80004005

JS small game running bear and cat source code

Basic syntax of MySQL DDL and DML and DQL

FTP service and configuration

idea写web项目时报错Failed to load resource: the server responded with a status of 404 (Not Found)
![Hospital PACS source code PACS ultrasonic Department source code DICOM image workstation source code [source code free sharing]](/img/7d/c309b7b0b919df44b5c1461d79e7e7.png)
Hospital PACS source code PACS ultrasonic Department source code DICOM image workstation source code [source code free sharing]

openEuler 资源利用率提升之道 01:概论
随机推荐
Hcip day 10 (initial BGP border gateway protocol)
uva1467
uva1445
FTP服务与配置
Huawei then responded to the rumor of "cleaning up employees over the age of 34". How can programmers cope with the "35 year old crisis"?
JVM initial
Data Lake: introduction to Apache Hudi
What is the security of Treasury reverse repo
关于Aries框架增删改查-查Demo
OSPF comprehensive experimental configuration
B. Eastern Exhibition- Codeforces Round #703 (Div. 2)
21st day of written test mandatory training
Express built-in Middleware
正則錶達式 \b \B 深入淺出理解單詞邊界的匹配
Hcip day 9 notes (OSPF routing feedback, routing policy, and Configuration Guide)
C文件操作详解
IO流分类整理
Industrial controller, do you really know your five insurances and one fund?
Cache component status when Vue components are switched, that is, dynamic components keep alive dynamic components and asynchronous components
Gpushare.com | 如何使用TensorBoardX可视化工具?