#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. hdu2112 HDU Today

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2112 题目分类:SPFA算法+map容器 错误点:红色标记部分 代码: #include<bit ...

  2. 16位图像Alpha混合的实现(用汇编写的,比MMX还要快)

    Alpha 混合的算法很简单,基于下面的公式就可以实现: D := A * (S - D) / 255 + D D 是目标图像的像素, S 是源图像的像素 A 是 Alpha 值, 0 为全透明, 2 ...

  3. poj3621 Sightseeing Cows --- 01分数规划

    典型的求最优比例环问题 參考资料: http://blog.csdn.net/hhaile/article/details/8883652 此题中,给出每一个点和每条边的权值,求一个环使 ans=∑点 ...

  4. Kendo UI开发教程(14): Kendo MVVM 数据绑定(三) Click

    Click绑定可以把由ViewModel定义的方法不绑定到目标DOM的click事件.当点击目标DOM元素时触发ViewModel的对应方法.例如: 使用Click绑定 1 <div id=&q ...

  5. BZOJ 1176([Balkan2007]Mokia-CDQ分治-分治询问)

    1176: [Balkan2007]Mokia Time Limit: 30 Sec   Memory Limit: 162 MB Submit: 185   Solved: 94 [ Submit] ...

  6. 初尝Java序列化/反序列化对象

    看个类: package com.wjy.bytes; import java.io.Serializable; public class ObjTest implements Serializabl ...

  7. 10324 - Zeros and Ones

    Problem N Zeros and Ones Input: standard input Output: standard output Time Limit: 2 seconds Memory ...

  8. 获得树形json串

    public class TreeNode { private long nodeId;     private String nodeName;     private long fatherNod ...

  9. 每天一个JavaScript实例-html5拖拽

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  10. A Game of Thrones(3) - Daenerys

    Her brother held the gown up for her inspection. “This is beauty. Touch it. Go on. Caress(爱抚,抚抱) the ...