当前位置:网站首页>Map insert element
Map insert element
2022-07-22 17:31:00 【joker_ 0030】
#include <iostream>
#include <map>
#include<algorithm>
using namespace std;
void fun(pair<int, char> pr)
{
cout << pr.first << pr.second << endl;//first Represents the key value ,second Represents the actual value .
}
void MapConstruct()
{
// rename pair.
typedef pair<int, char> in_pair;
// Iterative function , Used to detect when map When there are the same key values , Whether the actual value is inserted successfully .
pair<map<int, char>::iterator, bool> pr;//
// Define the object , And the assignment .( Insert value )
map<int, char> db;//< Key value , actual value >
db.insert(pair<int, char>(1, 'a'));// Need and map There is a one-to-one correspondence between the types of .
db.insert(in_pair(2, 'b'));
db.insert(in_pair(4, 'c'));
db.insert(in_pair(10, 'c'));
db.insert(in_pair(7, 'c'));
db.insert(in_pair(6, 'c'));
db.insert(in_pair(5, 'c'));
// Iterative function , Insert value
map<int, char>::iterator ite = db.begin();
ite++;
ite++;
ite++;
db.insert(ite,in_pair(3, 'c'));// The inserted value is not inserted into a position with a subscript of four , But where it should exist .
// Insert a paragraph
map<int, char>db1;
db1.insert(in_pair(8, 'b'));
db1.insert(in_pair(9, 'b'));
db1.insert(db.begin(),db.end());
// initialization
map <int, char>db2(db1);
map<int, char>db3(db2.begin(),db2.end());
// Output .
for_each(db.begin(),db.end(),fun);
for_each(db1.begin(),db1.end(),fun);
for_each(db2.begin(),db2.end(),fun);
for_each(db3.begin(),db3.end(),fun);
}
int main()
{
MapConstruct();
system("pause");
return 0;
}
边栏推荐
- flink sql 可以查询 clickhouse 吗
- LCD笔记(2)Framebuffer驱动程序框架
- NFS Shared Storage Service
- LCD notes (1) LCD hardware operation principle of different interfaces
- 对称式加密与非对称式加密的对比
- 什么是NumPy?
- 大佬们,flink sql job往yarn提交作业,报不能执行sql错误,本地执行不报错,服务器
- 【学习笔记之菜Dog学C】深入理解数组与指针
- ssrf漏洞攻击内网Redis复现
- Openeuler is ambitious, open source huizhichuang future | 2022 open atom global open source summit openeuler sub forum is about to open
猜你喜欢
LCD笔记(1)不同接口的LCD硬件操作原理
NFTFi赛道版图概览
分享我们的首次Otherside之旅
《PyTorch深度学习实践》-B站 刘二大人-day1
Android 面试题:你说一下 PendingIntent 和 Intent 的区别?
Understand five popular NFT delivery methods and their advantages and disadvantages
Pytorch deep learning practice-b station Liu erden-day1
Spark advanced features, 220720,
浏览器页面的渲染流程
了解 5 种流行的 NFT 投放方式及其优缺点
随机推荐
抖音怎么注销账号?操作流程步骤有哪些?
C语言分支结构和循环结构(1)
What is numpy?
MVC模式和三层架构
Pytorch deep learning practice-b station Liu erden-day1
What if only the mouse displays when win11 is turned on?
What are the ways of configuring Apache virtual hosts
NFTFi赛道版图概览
Simply understand what SaaS is? What is the difference between SAAS and traditional software?
How to download and install xshell plus6
深度解决npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
Ruoyi antd reported an error when using yarn install: the file c:\users\administrator\appdata\roaming\npm\yarn.ps1 could not be loaded
Network Security Learning (Qianfeng network security notes) 5 -- NTFS security permissions
unity3d-GameObject组件
LCD笔记(3)写出LCD基本驱动框架
SQL language (foundation 1)
重装Win11系统如何在线一键进行?
1312. 让字符串成为回文串的最少插入次数
STL resize容量规律集合
【C语言趣味实验】