当前位置:网站首页>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
边栏推荐
- Service developers publish services based on EDAs
- 5g/4g wireless networking scheme for brand chain stores
- How web pages interact with applets
- How can Huawei online match improve the success rate of player matching
- Modules golang
- MySQL develops small mall management system
- Hands on deep learning (37) -- cyclic neural network
- Basic principle of servlet and application of common API methods
- Uniapp--- initial use of websocket (long link implementation)
- Devop basic command
猜你喜欢
A little feeling
Intelligent gateway helps improve industrial data acquisition and utilization
C # use gdi+ to add text to the picture and make the text adaptive to the rectangular area
Use the data to tell you where is the most difficult province for the college entrance examination!
mmclassification 标注文件生成
Hands on deep learning (44) -- seq2seq principle and Implementation
MongoDB数据日期显示相差8小时 原因和解决方案
直方图均衡化
JDBC and MySQL database
How can people not love the amazing design of XXL job
随机推荐
System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
Ruby time format conversion strftime MS matching format
按键精灵打怪学习-识别所在地图、跑图、进入帮派识别NPC
Service developers publish services based on EDAs
C语言指针面试题——第二弹
libmysqlclient. so. 20: cannot open shared object file: No such file or directory
Native div has editing ability
uniapp 处理过去时间对比现在时间的时间差 如刚刚、几分钟前,几小时前,几个月前
Hands on deep learning (III) -- Torch Operation (sorting out documents in detail)
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
7-17 crawling worms (15 points)
2020-03-28
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
How to teach yourself to learn programming
MySQL case
Realsense of d435i, d435, d415, t265_ Matching and installation of viewer environment
Hands on deep learning (41) -- Deep recurrent neural network (deep RNN)
Reprint: summation formula of proportional series and its derivation process
C # use ffmpeg for audio transcoding
基于线性函数近似的安全强化学习 Safe RL with Linear Function Approximation 翻译 2