博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c++ map 官方样例
阅读量:7011 次
发布时间:2019-06-28

本文共 1746 字,大约阅读时间需要 5 分钟。

#include 
#include
#include
#include
template
void print_map(Map& m){ std::cout << '{
'; for(auto& p : m) std::cout << p.first << ":" << p.second << ' '; std::cout << '}'<
map1; map1["something"] = 69; map1["anything"] = 199; map1["that thing"] = 50; std::cout << "map1= "; print_map(map1); //range constructor //从anything到结尾 map
iter(map1.find("anything"), map1.end()); cout << "\niter= "; print_map(iter); cout << "map1= "; print_map(map1); //copy construct map
copied(map1); cout << "\ncopied= "; print_map(copied); cout << "map1 = "; print_map(map1); //move construct map
moved(std::move(map1)); cout<
<<"moved = "; print_map(moved); cout<<"map1 = ";print_map(map1); //initalizer list constructor const map
init{ { "this",100}, { "can",100}, { "be",100}, { "const",100}, }; cout<<"\ninit = ";print_map(init); //custom key class option 1; //use a comparison struct map
mag = { { { 5,-12},13}, { { 3,4},5}, { { 8,-15},17} }; for(auto p:mag) cout<<"The magnitude of("<
<<", "<
<<") is " <
<
magy(cmplambda); //various ways of inserting elements: magy.insert(pair
({ 5,-12},13)); magy.insert({ { 3,4},5}); magy.insert({Point{ -8.0,-15.0},17}); cout<<"\n"; for(auto p :magy) { cout<<"The magnitude of { "<
<<". "<
<<") is " <
<<"\n"; } map
::iterator it; //use iterator cout<<'\n'; for(it=magy.begin();it!=magy.end();it++) { cout<<"The magnitude of { "<
first.x <<". "<
first.y<<") is " <
second<<"\n"; } return 0;}

 原文地址:https://en.cppreference.com/w/cpp/container/map/map

posted on
2018-07-21 23:08 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/shuiyonglewodezzzzz/p/9348472.html

你可能感兴趣的文章
Android项目之旅三 简易Mp3播放器从获取服务器端Mp3信息
查看>>
将一个数组中的奇元素全部移到数组的前半部分,即将奇偶元素分开
查看>>
无需SDK的统计工具,让哥赚了个iphone6
查看>>
没有做数据备份 网站随时毁于一旦
查看>>
Python学习笔记
查看>>
js中json与字符串转换小例子
查看>>
学习笔记-实验楼项目课(Linux桌面字典)
查看>>
Spring基础问答
查看>>
iOS8 相机拍照问题 Snapshotting a view
查看>>
comparable 接口的使用示例
查看>>
剑指Offer之重建二叉树(题6)
查看>>
strace-跟踪进程执行时的系统调用
查看>>
三个数找最大 1.0
查看>>
判断大端与小端
查看>>
计算机科学技术基础知识之多媒体知识
查看>>
如何禁用笔记本键盘
查看>>
第一次开博客,虽然有点晚了,用来鞭策激励一下自己,加油!
查看>>
4.4作业(变更管理+安全管理)
查看>>
(二)JSP语法详细介绍--指令元素
查看>>
python 数据库处理
查看>>