STL - 容器 - Map(一)
2023-09-11 14:16:56 时间
MapTest.cpp
#include <map> #include <string> #include <iostream> #include <algorithm> #include "MapTest.h" using namespace std; void MapTest::simpleEnumeration() { map<string,double> coll { { "tim", 9.9 }, { "struppi", 11.77 } } ; // for range-based enumeration cout << "for range-based enumeration: " << endl; for (auto elem : coll) { cout << elem.first << ": " << elem.second << endl; } // iterating cout << "iterating: " << endl; map<string, double>::iterator pos; for (pos = coll.begin(); pos != coll.end(); ++pos) { cout << pos->first << ": " << pos->second << endl; } // square the value of each element: for_each (coll.begin(), coll.end(), [] (pair<const string,double>& elem) { elem.second *= elem.second; }); // print each element: cout << "for_each lambda enumeration: " << endl; for_each (coll.begin(), coll.end(), [] (const map<string,double>::value_type& elem) { cout << elem.first << ": " << elem.second << endl; }); } void MapTest::run() { printStart("simpleEnumeration()"); simpleEnumeration(); printEnd("simpleEnumeration()"); }
运行结果:
--------------- simpleEnumeration(): Run Start ----------------
for range-based enumeration:
truppi: 11.77
im: 9.9
terating:
truppi: 11.77
im: 9.9
or_each lambda enumeration:
truppi: 138.533
im: 98.01
--------------- simpleEnumeration(): Run End ----------------
相关文章
- python数据分析apply(),map(),applymap()用法归纳
- mAP/NAS
- 从头认识java-15.7 Map(7)-TreeMap与LinkedHashMap
- C/C++知识要点2——STL中Vector、Map、Set容器的实现原理
- ES6(十一)Set和Map
- Java的Map中的map.keySet()方法
- [转]jdk8中map新增的merge方法
- [转]Java复制Map对象(深拷贝与浅拷贝)
- 获取List<Map<String, Object>中Map的属性值列表,获取所有map对象的某个属性列表
- 怎么在java 8的map中使用stream
- ArcGIS Google Map 增加虚拟图层(MapImageLayer)(转载)
- vue项目构建实战基础知识:SPA理解/RESTful接口介绍/static目录配置/axios封装/打包时map文件去除
- TypeScript Map 对象
- 详解C++ STL map 容器
- 关于map和vector容器的简单使用
- 十.jQuery源码分析之.map()