#include <iostream>
#include <string>
#include <map> using namespace std; typedef pair<float, string> TIntStrPair; map <int, TIntStrPair> IIStrMap; //<int, <float,string>> map <string, string> StrStrMap; // <string,string> int main(int argc, char *argv[]) { map <int ,string> IntStrMap; IntStrMap.insert(pair<int,string>(, "Tom"));
IntStrMap.insert(pair<int,string>(, "Jimes"));
IntStrMap.insert(pair<int, string>(, "Mary"));
IntStrMap.insert(make_pair(, "Adom")); //use make_pair(); map<int,string>::iterator it; for (it = IntStrMap.begin(); it != IntStrMap.end(); it++) {
cout << it->first << " " << it->second << endl;
} cout << "-------------------------------" << endl; IIStrMap.insert(pair<int, TIntStrPair>(, pair<float, string>(1.1, "Tom")));
IIStrMap.insert(pair<int, TIntStrPair>(, pair<float, string>(2.1, "Fantex"))); IIStrMap.insert(make_pair(, make_pair(3.2, "Jimes")));//use make_pair() map<int, TIntStrPair>::iterator It; for (It = IIStrMap.begin(); It != IIStrMap.end(); It++) {
cout << It->first << " " << It->second.first << " " << It->second.second << endl;
} cout << "----------------------------------" << endl; StrStrMap.insert(pair<string,string>("md5sum", "true"));
StrStrMap.insert(pair<string,string>("sigcheck", "false"));
StrStrMap.insert(pair<string, string>("ors_path", "/sdcard/ors")); StrStrMap.insert(make_pair("time_zone", "CTS"));// use make_pair(); cout << "list the value " << endl; map<string, string>::iterator iter; for (iter = StrStrMap.begin(); iter != StrStrMap.end(); iter++) {
cout << iter->first << " = " << iter->second << endl;
} cout << "change the value " << endl; iter = StrStrMap.begin(); iter = StrStrMap.find("md5sum");
iter->second = "false"; cout << "list the vale after change it " << endl; for (iter = StrStrMap.begin(); iter != StrStrMap.end(); iter++) {
cout << iter->first << " = " << iter->second << endl;
} cout << "----------------------------------------" << endl; cout << "erase the element " << endl; iter = StrStrMap.begin(); iter = StrStrMap.find("md5sum");
StrStrMap.erase(iter); for (iter = StrStrMap.begin(); iter != StrStrMap.end(); iter++) {
cout << iter->first << " = " << iter->second << endl;
} return ; }

C++ map简单运用的更多相关文章

  1. C++关联容器<map>简单总结

    C++关联容器<map>简单总结 map提供大小可变的关联容器,基于关联键值高效检索元素值.当你处理键值对的数据是,都可以考虑使用map关联容器. 特点: 大小可变的关联容器,基于关联键值 ...

  2. Android-Kotlin-区间与for&List&Map简单使用

    区间与for: package cn.kotlin.kotlin_base04 /** * 区间与for */ fun main(args: Array<String>) { /** * ...

  3. 充电时间 Go中的数组、切片、map简单示例

    数组是固定长度的,依稀让我想起了VB:切片是动态的:map一般是键值对 package main import ( "fmt" ) func main() { var userna ...

  4. 题目1069:查找学生信息(STL的map简单应用)

    题目描述: 输入N个学生的信息,然后进行查询. 输入:                        输入的第一行为N,即学生的个数(N<=1000) 接下来的N行包括N个学生的信息,信息格式如 ...

  5. JS Map 简单实现

    /* * MAP对象,实现MAP功能 * * 接口: * size() 获取MAP元素个数 * isEmpty() 判断MAP是否为空 * clear() 删除MAP所有元素 * put(key, v ...

  6. Java List&Map简单初始化方法

    Java中List与Map初始化的一些写法 // InitCollections.java - sample of init collect package com.util; import java ...

  7. STL map简单使用

    #include <map> #include <iostream> //pair使用头文件iostream using namespace std; int main() { ...

  8. cocos2d-x3.0 Vector和Map简单使用

    Vector<Node*> vec; auto node1 = Node::create(); node1->setTag(1); vec.pushBack(node1); auto ...

  9. java的Set, List, Map简单介绍

    Set, List, Map Set和List,Map都是集合,Set和List都是继承于Collection接口,而Map不是. 1.Map(映射) :Map是以key,Value的形式存储数据的映 ...

随机推荐

  1. HDU 1242——Rescue(优先队列)

    题意: 一个天使a被关在迷宫里,她的很多小伙伴r打算去救她.求小伙伴就到她须要的最小时间.在迷宫里有守卫.打败守卫须要一个单位时间.假设碰到守卫必须要杀死他 思路: 天使仅仅有一个,她的小伙伴有非常多 ...

  2. LAN路由

    一.实验的目的:   实现不同子网之前的信息交流      二.如果 1.虚拟子网 VMnet8:192.168.233.0/24 VMnet1:172.16.1.0/24 2.虚拟机vm1 ip:1 ...

  3. YUV格式具体解释

    YUV是指亮度參量和色度參量分开表示的像素格式,而这样分开的优点就是不但能够避免相互干扰,还能够减少色度的採样率而不会对图像质量影响太大.YUV是一个比較笼统地说法,针对它的详细排列方式,能够分为非常 ...

  4. Android仿iOS7的UISegmentedControl 分段

    效果图: 这里仅仅简单做了两个button的. 首先是两个button的背景: res/drawable/seg_left.xml <?xml version="1.0" e ...

  5. tomcat各版本和jsp、jstl、servlet的依赖关系(转)

    Servlet / JSP / Tomcat  Version  Servlet/ JSP    Tomcat  2.5/2.1 6.0.18 2.4/2.0 5.5.27 2.3/1.2 4.1.3 ...

  6. ssh 即使主机,同nohup背景脚本

    下面的脚本工具:先从本地副本的脚本到远程主机,然后ssh即使在远程主机,脚本的运行副本前(因为脚本需要运行很长,它运行在后台),该脚本仅用于备忘录,如果请指点不足! #!/bin/bash cd /t ...

  7. 轻松学习之Linux教程六 正則表達式具体解释

    本系列文章由@超人爱因斯坦出品.转载请注明出处. 作者:超人爱因斯坦    个人站点:http://www.hpw123.net          文章链接:http://hpw123.net/a/L ...

  8. ubuntu12 下怎样上网

    1,host 就是WIN7 使用WIFI上网 2.打开设置你的VM 8 edit--Virutal network editor--VMnet0--Bridged (connect VMs to di ...

  9. Tkinter隐藏窗口再让他显示出来的例子

    隐藏主要是 : withdraw()函数. 重新显示出来主要是: update()和deiconify()函数. 来源:http://www.blog.pythonlibrary.org/2012/0 ...

  10. 恩布企业 IM 安卓端 1.3,服务端 1.12 公布

    恩布企业IM的 Android 安卓开源手机client EntboostIM 公布 1.3 版本号.同一时候恩布IM服务端更新至 1.12 版本号; 安卓端主要更新内容: 添加收发手机文件功能: 登 ...