#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. 无锁队列--基于linuxkfifo实现

    一直想写一个无锁队列,为了提高项目的背景效率. 有机会看到linux核心kfifo.h 原则. 所以这个实现自己仿照,眼下linux我们应该能够提供外部接口. #ifndef _NO_LOCK_QUE ...

  2. [C++]const修饰符

    Date: 2014-1-1 Summary: const 修饰符笔记 Contents: 1.const 修饰符 声明一个常量数据类型 , 在编译时就确定数据类型 2.const 与 指针 一般情况 ...

  3. SVNKit getFileFromSVN

    /* * ==================================================================== * Copyright (c) 2004-2011 ...

  4. 开源搜索引擎评估:lucene sphinx elasticsearch

    开源搜索引擎评估:lucene sphinx elasticsearch 开源搜索引擎程序有3大类 lucene系,java开发,包括solr和elasticsearch sphinx,c++开发,简 ...

  5. RH033读书笔记(17) - Summary

    End of Unit 1 • Questions and Answers • Summary • Open source and the right to modify • The GNU Proj ...

  6. Fluentd: Open Source Log Management

    Fluentd: Open Source Log Management "Fluentd" is an open-source tool to collect events and ...

  7. 在MVC应用程序中动态加载PartialView

    原文:在MVC应用程序中动态加载PartialView 有时候,我们不太想把PartialView直接Render在Html上,而是使用jQuery来动态加载,或是某一个事件来加载.为了演示与做好这个 ...

  8. hdu 1542 Atlantis(段树&amp;扫描线&amp;面积和)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  9. hdu 1251 统计难题 (map水过)

    # include <stdio.h> # include <algorithm> # include <string> # include <map> ...

  10. Java整型数组的最大长度到底有多长?

    Java整型数组的最大长度到底有多长? 今天上网查了一下,各种说法都有,这个问题似乎总困扰我们Java初学者,无奈,只好自己试了一下,以下是我的测试代码,如果有错误,还望不吝赐教! 使用eclipse ...