当前位置:网站首页>Map container
Map container
2022-07-04 10:15:00 【Wildcraner】
One 、 Insert the way
map<int, int> m;
// The first way to insert
m.insert(pair<int, int>(1, 10));
// The second insertion method
m.insert(make_pair(2, 20));
// Third insertion method
m.insert(map<int, int>::value_type(3, 30));
// Fourth insertion method
m[4] = 40;
result
key = 1 value = 10
key = 2 value = 20
key = 3 value = 30
key = 4 value = 40
Be careful
If key = 1 value = 10
Already exist , How to change ?
map<int, int> m;
// The first way to insert
m.insert(pair<int, int>(1, 10));
m.insert(pair<int, int>(1, 12));
// The second insertion method
m.insert(make_pair(1, 20));
// Third insertion method
m.insert(map<int, int>::value_type(1, 30));
// Fourth insertion method
//m[1] = 40;
printMap(m);
Running results key = 1 value = 10
So we need to change it in the fourth way :m[1] = 40;
Two 、 Traverse ( Using iterators )
void printMap(map<int, int>& m)
{
for (map<int, int>::iterator it = m.begin(); it != m.end(); it++)
{
cout << "key = " << it->first << " value = " << it->second << endl;
}
cout << endl;
}
map<int, int>::iterator it
-> Define an iterator itit->first
map Container of key value it->second
map Container of value value
边栏推荐
- 直方图均衡化
- 【Day1】 deep-learning-basics
- Batch distribution of SSH keys and batch execution of ansible
- Regular expression (I)
- 技术管理进阶——如何设计并跟进不同层级同学的绩效
- Container cloud notes
- Hands on deep learning (39) -- gating cycle unit Gru
- Golang Modules
- Hands on deep learning (40) -- short and long term memory network (LSTM)
- IIS configure FTP website
猜你喜欢
Mmclassification annotation file generation
PHP代码审计3—系统重装漏洞
A little feeling
Write a mobile date selector component by yourself
MongoDB数据日期显示相差8小时 原因和解决方案
2. Data type
转载:等比数列的求和公式,及其推导过程
Development guidance document of CMDB
Hands on deep learning (32) -- fully connected convolutional neural network FCN
Hands on deep learning (44) -- seq2seq principle and Implementation
随机推荐
Histogram equalization
AUTOSAR from getting started to mastering 100 lectures (106) - SOA in domain controllers
Laravel文档阅读笔记-How to use @auth and @guest directives in Laravel
Exercise 7-2 finding the maximum value and its subscript (20 points)
libmysqlclient. so. 20: cannot open shared object file: No such file or directory
Hands on deep learning (36) -- language model and data set
Hands on deep learning (38) -- realize RNN from scratch
uniapp 小于1000 按原数字显示 超过1000 数字换算成10w+ 1.3k+ 显示
Advanced technology management - how to design and follow up the performance of students at different levels
View CSDN personal resource download details
Today's sleep quality record 78 points
2021-08-11 function pointer
Hands on deep learning (34) -- sequence model
Golang Modules
AUTOSAR从入门到精通100讲(106)-域控制器中的SOA
System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
Servlet基本原理与常见API方法的应用
Hands on deep learning (46) -- attention mechanism
Realsense of d435i, d435, d415, t265_ Matching and installation of viewer environment
Dos:disk operating system, including core startup program and command program