当前位置:网站首页>Std:: Map initialization
Std:: Map initialization
2022-06-13 05:01:00 【Snow * sleet * snow】
Static initialization and direct assignment
#include <iostream>
#include <map>
#include <string>
#include <string_view>
void print_map(std::string_view comment, const std::map<std::string, int>& m)
{
std::cout << comment;
for (const auto& [key, value] : m) {
std::cout << key << " = " << value << "; ";
}
std::cout << "\n";
}
int main()
{
// Create a map of three strings (that map to integers)
// Static list initialization
std::map<std::string, int> m {
{
"CPU", 10}, {
"GPU", 15}, {
"RAM", 20}, };
print_map("Initial map: ", m);
// Direct assignment
m["CPU"] = 25; // update an existing value
m["SSD"] = 30; // insert a new value
print_map("Updated map: ", m);
}
Initial map: CPU = 10; GPU = 15; RAM = 20;
Updated map: CPU = 25; GPU = 15; RAM = 20; SSD = 30;
ff
边栏推荐
- Kaggle time series tutorial
- Section 8 - Practical commissioning techniques
- Spread your wings and soar
- Sub paragraph of Chapter 16
- [leetcode]- binary search
- Bomb disposal cat
- Stepping on a horse (one stroke)
- OpenCV中的saturate操作(饱和操作)究竟是怎么回事
- Explain the opencv function cv:: add() in detail, and attach sample code and running results of various cases
- Analysis on the usage, response and global delivery of provide/inject
猜你喜欢

LeetCode第297场周赛(20220612)

Spread your wings and soar

2021TPAMI/图像处理:Exploiting Deep Generative Prior for Versatile Image Restoration and Manipulation
![[JS solution] leedcode 200 Number of islands](/img/c1/bcdb3fc079c634a9a1b3d0fc264987.png)
[JS solution] leedcode 200 Number of islands

Bomb disposal cat

Solution to sudden font change in word document editing

自动评教脚本使用的配置

Leetcode game 297 (20220612)

Reductive elimination

Configuration used by automatic teaching evaluation script
随机推荐
135. distribute candy
The games that you've tasted
[JS solution] leedcode 117 Populate the next right node pointer II for each node
Chapter 17 free space management
Design system based on MVC using javeswingjdbc
Explain the role of key attribute in V-for
Conception d'un système basé sur MVC avec javaswing JDBC
[leetcode]- binary search
Bm1z002fj-evk-001 startup evaluation
关于匿名内部类
利用Javeswingjdbc基於mvc設計系統
Keil uses j-link to burn the code, and an error occurs: Flash download failed - one of the "Cortex-M3" solutions
Analysis of the principle of V-model and its application in user defined components
Embedded hardware: electronic components (1) resistance capacitance inductance
C language learning log 10.5
Regular expressions in QT
Kaggle 时间序列教程
Spread your wings and soar
Advantages of win8.1 and win10
C language exercise 1