当前位置:网站首页>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
边栏推荐
- Mmclassification annotation file generation
- Exercise 8-7 string sorting (20 points)
- AUTOSAR从入门到精通100讲(106)-域控制器中的SOA
- Advanced technology management - how to design and follow up the performance of students at different levels
- 用数据告诉你高考最难的省份是哪里!
- H5 audio tag custom style modification and adding playback control events
- [200 opencv routines] 218 Multi line italic text watermark
- Exercise 9-3 plane vector addition (15 points)
- Service developers publish services based on EDAs
- Kotlin 集合操作汇总
猜你喜欢
PHP code audit 3 - system reload vulnerability
Hands on deep learning (44) -- seq2seq principle and Implementation
品牌连锁店5G/4G无线组网方案
xxl-job惊艳的设计,怎能叫人不爱
C # use gdi+ to add text to the picture and make the text adaptive to the rectangular area
uniapp 处理过去时间对比现在时间的时间差 如刚刚、几分钟前,几小时前,几个月前
Hands on deep learning (41) -- Deep recurrent neural network (deep RNN)
Histogram equalization
Reasons and solutions for the 8-hour difference in mongodb data date display
C # use ffmpeg for audio transcoding
随机推荐
Ruby time format conversion strftime MS matching format
System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
Hands on deep learning (46) -- attention mechanism
Button wizard business running learning - commodity quantity, price reminder, judgment Backpack
Devop basic command
Container cloud notes
Kotlin: collection use
IIS configure FTP website
Golang type comparison
Kubernetes CNI 插件之Fabric
What is devsecops? Definitions, processes, frameworks and best practices for 2022
今日睡眠质量记录78分
If the uniapp is less than 1000, it will be displayed according to the original number. If the number exceeds 1000, it will be converted into 10w+ 1.3k+ display
回复评论的sql
Dynamic memory management
C语言指针经典面试题——第一弹
System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
Development guidance document of CMDB
Reprint: summation formula of proportional series and its derivation process
Advanced technology management - how to design and follow up the performance of students at different levels