#include <stdio.h>
#include <map>
using namespace std; int main(){
map<int, int> mp;
for (int i = 0; i < 10; i ++){
mp[i] = i;
} //count
if (mp.count(0)) {
printf("yes\n");
} else {
printf("no\n");
} //find
map<int, int>::iterator it_find=mp.begin();
it_find = mp.find(9);
if(it_find != mp.end()) {
it_find->second = 20;
} else {
printf("nno\n");
} //erase
//mp.erase(it_find); mp.insert(map<int, int>::value_type(100,100)); //traversal
map<int, int>::iterator it;
for (it = mp.begin(); it != mp.end(); it++){
printf("%d-->%d\n", it->first, it->second);
} return 0;
}

c++ map迭代器的更多相关文章

  1. 给jdk写注释系列之jdk1.6容器(6)-HashSet源码解析&Map迭代器

    今天的主角是HashSet,Set是什么东东,当然也是一种java容器了.      现在再看到Hash心底里有没有会心一笑呢,这里不再赘述hash的概念原理等一大堆东西了(不懂得需要先回去看下Has ...

  2. 关于set和map迭代器支持的运算

    问题: 曾经想遍历一个set遍历.当时是这样写的: set<int>::iterator b = a.begin()+1 后来发现程序报错.究其原因是,set迭代器不支持加减数操作. 查看 ...

  3. Planning The Expedition(暴力枚举+map迭代器)

    Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is t ...

  4. Minimum Sum of Array(map迭代器)

    You are given an array a consisting of n integers a1, ..., an. In one operation, you can choose 2 el ...

  5. Coins and Queries(map迭代器+贪心)

    题意 n个硬币,q次询问.第二行给你n个硬币的面值(保证都是2的次幂!).每次询问组成b块钱,最少需要多少个硬币? Example Input 5 42 4 8 2 4851410 Output 1- ...

  6. vector map迭代器失效解决方案

    vector : iter = container.erase(iter);    //erase的返回值是删除元素下一个元素的迭代器 vector<int>::iterator it = ...

  7. Map迭代器

            今天用到了,发现不会,随手谷歌之,整理如下. //Map是接口,刚才在那new Map,汗颜 Map<Character,Integer> mm = new HashMap ...

  8. 【c++】map 迭代器删除演示样例

    C++ STL中的map是很常见的.通常我们用例如以下方式来遍历,而且删除map中的一些entry: map<int, int> mp; mp.insert(make_pair(1,1)) ...

  9. const 迭代器和 const_iterator (vector/set/map)

    vector: 如同一般复合类型一样,vector 迭代器也可以声明成: const vector<int>::iterator it1 = v.begin(); vector<in ...

随机推荐

  1. C++学习之继承中的访问控制

    我们通常认为一个类有两种不同的用户:普通用户 和 类的实现者.其中,普通用户编写的代码使用类的对象,这部分代码只能访问类的公有(接口)成员:实现者则负责编写类的成员和友元的代码,成员和友元既能访问类的 ...

  2. cc2540 usbdongle 安装驱动失败的终极解决方法 【原创,多图】

    Ghost winxp win7系统安装CC2540 usbdongle CDC驱动程序 [重要提示] 因为非常多朋友使用Ghost系统.导致安装cdc驱动时安装不成功,出现 "INF中的服 ...

  3. docker(1):virtualbox 安装CoreOS系统,配置registry-mirror

    本文的原文连接是: http://blog.csdn.net/freewebsys/article/details/51093850 未经博主同意不得转载. 博主地址是:http://blog.csd ...

  4. pat-1087【最短路径】

    近期一次pat考试中的最后一题.事实上玩算法这东西就像打魔兽.不能光有思想上的高度,微操必须实打实.就这么个迪杰斯特拉算法.多少教科书上都讲烂了. 可是现场又有多少人是敲对的呢?不能光停留在理解上.必 ...

  5. Uva 10036 - Divisibility

    Consider an arbitrary sequence of integers. One can place + or - operators between integers in the s ...

  6. HDU 1299Diophantus of Alexandria

    Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  7. document.getElementById方法在火狐和谷歌浏览器兼容

    转自:http://www.office68.com/computer/6505.html 对于前台设计,浏览不兼容是一个很头晕的事情,为此记录下来与大家分享,并供日后自己参考. 例:有一个名为pwd ...

  8. LIBTOOL is undefined 问题的解决方法

    configure.ac:10: error: possibly undefined macro: AC_PROG_LIBTOOL If this token and others are legit ...

  9. Hadoop 的使用

    hadoop:hadoop启动:./sbin/start-dfs.shhadoop关闭:./sbin/stop-dfs.shbin文件用于在HDFS创建数据HDFS 中创建用户目录:./bin/hdf ...

  10. P2085最小函数值(优先队列)

    P2085 最小函数值(minval) 题目描述 有n个函数,分别为F1,F2,...,Fn.定义Fi(x)=Ai*x^2+Bi*x+Ci (x∈N*).给定这些Ai.Bi和Ci,请求出所有函数的所有 ...