当前位置:网站首页>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
边栏推荐
- Design system based on MVC using javeswingjdbc
- 详解OpenCV的函数cv::add(),并附各种情况的示例代码和运行结果
- 自动评教脚本使用的配置
- [LeetCode]-二分查找
- Article 49: understanding the behavior of new handler
- Clause 31: avoid default capture mode
- RMQ、LCA
- 使用EasyDarwin+FFmpeg实现rtsp推流
- Search DFS and BFS
- Analysis of the principle of V-model and its application in user defined components
猜你喜欢

Sort (internal sort) + external sort

Simple-SR:Best-Buddy GANs for Highly Detailed Image Super-Resolution论文浅析

Sampo Lock

Regular expressions in QT

Analysis of scoped attribute principle and depth action selector

Bm1z002fj-evk-001 startup evaluation

Spread your wings and soar

Conception d'un système basé sur MVC avec javaswing JDBC

Advantages of win8.1 and win10

C language learning log 1.22
随机推荐
Four methods for judging JS data types and user-defined methods
Construction problem of D Xiaohong
QT client development -- driver loading problem of connecting to MySQL database
Advanced C - Section 2 - pointers
Win8.1和Win10各自的優勢
Opencv image storage and reading
QT interface rendering style
C language learning log 1.19
Simple sr: Best Buddy Gans for highly detailed image super resolution Paper Analysis
135. distribute candy
Analysis of the principle of V-model and its application in user defined components
Search DFS and BFS
Draw a hammer
Spice story
Chapter 2 process management
Solution to sudden font change in word document editing
Force deduction 121 questions
Little C's Notepad
无限循环滚动代码阿里巴巴国际站店铺装修代码底图滚动黑色半透明显示效果自定义内容装修代码全屏显示
RuoYi-Cloud启动教程(手把手图文)