实践如下:

#include <iostream>
#include <map>
#include <string>
#include <typeinfo>
using namespace std; int main() {
cout << "Map 测试" << endl; //int i =1;
string name("jack");
pair<int, string> pair1(, name);
pair<int, string> pair2(, "老张"); map<int, string> map1;
map1.insert(pair1);
map1.insert(pair1);
map1.insert(pair2); map<int, string>::iterator it;
for (it = map1.begin(); it != map1.end(); it++) {
cout << (*it).first << "->" << (*it).second << endl;
} pair<string, string> pair21("张三", "张三");
pair<string, string> pair22("老张", "老张"); map<string, string> map2;
map2.insert(pair21);
map2.insert(pair21);
map2.insert(pair22); map<string, string>::iterator it2;
for (it2 = map2.begin(); it2 != map2.end(); it2++) {
cout << (*it2).first << "->" << (*it2).second << endl;
} map2.erase("张三");
cout << "再次遍历" << endl;
for (it2 = map2.begin(); it2 != map2.end(); it2++) {
cout << (*it2).first << "->" << (*it2).second << endl;
} map2.insert(pair<string, string>("老张2", "老张2"));
cout << "再次遍历2" << endl;
for (it2 = map2.begin(); it2 != map2.end(); it2++) {
cout << (*it2).first << "->" << (*it2).second << endl;
} cout << "测试结束" << endl;
return ;
}

C++ Map实践的更多相关文章

  1. mybatis oracle 插入自增记录 获取主键值 写回map参数

    网上搜了好多文章照着弄都返回不了主键给map, 实践证明要在传入的map参数里写回插入的主键,要这样写 <selectKey resultType="java.lang.Integer ...

  2. Python笔记(二)

    python笔记 函数式编程 函数 函数是Python内建支持一种封装(将大段代码拆成函数) 通过函数的调用,可以将复制的任务分解. 函数式编程(Functional Programming) 计算机 ...

  3. C++ Primer 学习笔记_35_STL实践与分析(9)--map种类(在)

    STL实践与分析 --map类型(上) 引: map是键-值对的集合. map类型通常能够理解为关联数组:能够通过使用键作为下标来获取一个值,正如内置数组类型一样:而关联的本质在于元素的值与某个特定的 ...

  4. MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example 1.4 Labeling the Map

    MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example 1.4 Labeling the Map 一.前言 MapServer拥有非常灵活的标签 ...

  5. MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.2 Static Map with Two Layers

    MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.2 Static Map with Two Layers 一.前言 上一篇博客< ...

  6. MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.1 A map with single layer

    MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.1 A map with single layer 一.前言 开始MapServer用 ...

  7. 『实践』百度地图给map添加右键菜单(判断是否为marker)

      var map; var s;//经度 var w;//纬度 $(document).ready(function(){ $(".mune").load("jsp/c ...

  8. golang 多维哈希(map,hashmap)实践随笔

    有些场景使用多维哈希来存储数据,时间复杂度恒定,简单粗暴好用.这里记录一下. 如下是三维哈希的简单示意图,建议层数不要太多,否则时间久了,自己写的代码都不认识. 下图是三维哈希在内存的存储形式,has ...

  9. Golang高效实践之array、slice、map

    前言 Golang的slice类型为连续同类型数据提供了一个方便并且高效的实现方式.slice的实现是基于array,slice和map一样是类似于指针语义,传递slice和map并不涉及底层数据结构 ...

随机推荐

  1. 转载: Ubuntu 在命令下,安装中文环境的方法。

    转载: https://blog.csdn.net/zhangchao19890805/article/details/52743380 安装英文版ubuntu,在打开含有中文字符文件时会乱码,有需要 ...

  2. 1.什么是bat文件

    bat文件是dos下的批处理文件.批处理文件是无格式的文本文件,它包含一条或多条命令.它的文件扩展名为 .bat 或 .cmd. 在命令提示下输入批处理文件的名称,或者双击该批处理文件,系统就会调用c ...

  3. 关于fastJson的几个问题

    1.将对象中为null的属性也给序列化出来 可以使用SerializaerFeature实现 JSON.toJSONString(gas, SerializerFeature.WriteMapNull ...

  4. 织梦DedeCMS栏目列表常见序号的调用标签

    我们在制作dedecms模板时,源代码中的[field:global name=autoindex/]标签很好用可以调用数字序号,此标签最简单的用法就是按内容条数来获取数字序号,但有的时候发现使用该标 ...

  5. Linux排查磁盘空间顺序解决空间不足问题

    1 先查看整个磁盘的情况 df    -h                     查看整台服务器的硬盘使用情况 cd    /                       进入根目录 du   -s ...

  6. 浅析Java泛型

    什么是泛型? 泛型是JDK 1.5的一项新特性,它的本质是参数化类型(Parameterized Type)的应用,也就是说所操作的数据类型被指定为一个参数,在用到的时候在指定具体的类型.这种参数类型 ...

  7. nginx第五天

    nginx的全局变量 变量 说明 $args 请求中的参数,如www.123.com/1.php?a=1&b=2的$args就是a=1&b=2 $content_length HTTP ...

  8. 手机端自适应缩放显示 js

    <script> var _width = parseInt(window.screen.width); var scale = _width/640; var ua = navigato ...

  9. spring data mongo API learn(转)

    显示操作mongo的语句,log4j里面加入: log4j.logger.org.springframework.data.mongodb.core=DEBUG, mongodb log4j.appe ...

  10. 动软代码生成器生成model

    model <#@ template language="c#" HostSpecific="True" #> <#@ output exte ...