#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. xcode 4.5 new feature __ ios6 新特性

    上两周看了wwdc 2012 developer session 400 - 412的视频,以下总结一下xcode4.5的新特性.(部分參考onevcat的文章,在此感谢.) @synthesize ...

  2. ios 从rgb array生成UIImage并显示,oc版

    ; ; const size_t Area = Width * Height; ; // rgba std::vector<uint8_t> output(Area*channles); ...

  3. ios12--简易购物车

    Assets.xcassets图片是拖到右边里面去的. // // ViewController.m // 03-综合练习 // #import "ViewController.h" ...

  4. BitmapFactory.decodeStream()获取bitmap返回null

    正常的图片缩放代码如: ByteArrayOutputStream baos = new ByteArrayOutputStream(); arg1.compress(Bitmap.CompressF ...

  5. 深入理解7816(1)---- 关于F/D和etu【转】

    本文转载自:http://blog.sina.com.cn/s/blog_4df8400a0101gkss.html 深入理解7816(1)---- 关于F/D和etu 对于刚接触智能卡的工程师来说, ...

  6. SVG可伸缩矢量图形

    SVG可伸缩矢量图形 总结 1.svg就像普通标签那么使用 2.svg是xml 3.svg是矢量图,而canvas是位图 学习要点 对HTML5中的SVG有初步的了解 什么是SVG 简单的说SVG文档 ...

  7. P1491 集合位置 次短路

    这个题是一个次短路的裸题,就是把最短路路径求出来之后依次删边,然后跑最短路,在这些情况里取最小值就行了. 题干: 每次有大的活动,大家都要在一起“聚一聚”,不管是去好乐迪,还是避风塘,或者汤姆熊,大家 ...

  8. sql 语句NVL()用法

    一NVL函数是一个空值转换函数 NVL(表达式1,表达式2) 如果表达式1为空值,NVL返回值为表达式2的值,否则返回表达式1的值. 该函数的目的是把一个空值(null)转换成一个实际的值.其表达式的 ...

  9. MSP430 G2553 Timer 中断总结

    目前总共用到了四个中断向量,我觉得已经把G2553的所有定时器中断都用到了. 定时器有两个,TA0与TA1,每个定时器又有两个中断向量 1,CCR0到达时的中断,在计数模式时候很有用,平时定时器的基本 ...

  10. ACM_“打老虎”的背后(简单并查集)

    “打老虎”的背后 Time Limit: 2000/1000ms (Java/Others) Problem Description: “习大大”自担任国家主席以来大力反腐倡廉,各地打击贪腐力度也逐步 ...