当前位置:网站首页>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
边栏推荐
- System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
- Native div has editing ability
- Kotlin: collection use
- Pcl:: fromrosmsg alarm failed to find match for field 'intensity'
- MySQL develops small mall management system
- uniapp 处理过去时间对比现在时间的时间差 如刚刚、几分钟前,几小时前,几个月前
- ASP. Net to access directory files outside the project website
- Hands on deep learning (41) -- Deep recurrent neural network (deep RNN)
- Hands on deep learning (34) -- sequence model
- 直方图均衡化
猜你喜欢

【Day1】 deep-learning-basics
What are the advantages of automation?

mmclassification 标注文件生成

Regular expression (I)

Hands on deep learning (III) -- Torch Operation (sorting out documents in detail)

For programmers, if it hurts the most...

Matlab tips (25) competitive neural network and SOM neural network

百度研发三面惨遭滑铁卢:面试官一套组合拳让我当场懵逼

Hands on deep learning (45) -- bundle search
Summary of reasons for web side automation test failure
随机推荐
Go context basic introduction
查看CSDN个人资源下载明细
Servlet基本原理与常见API方法的应用
Advanced technology management - how to design and follow up the performance of students at different levels
xxl-job惊艳的设计,怎能叫人不爱
Use the data to tell you where is the most difficult province for the college entrance examination!
The time difference between the past time and the present time of uniapp processing, such as just, a few minutes ago, a few hours ago, a few months ago
Button wizard business running learning - commodity quantity, price reminder, judgment Backpack
Reprint: summation formula of proportional series and its derivation process
Exercise 9-1 time conversion (15 points)
IIS configure FTP website
C语言指针面试题——第二弹
Normal vector point cloud rotation
Exercise 9-5 address book sorting (20 points)
Devop basic command
Log cannot be recorded after log4net is deployed to the server
【Day2】 convolutional-neural-networks
今日睡眠质量记录78分
Hands on deep learning (38) -- realize RNN from scratch
2021-08-11 function pointer