c++ map迭代器
#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迭代器的更多相关文章
- 给jdk写注释系列之jdk1.6容器(6)-HashSet源码解析&Map迭代器
今天的主角是HashSet,Set是什么东东,当然也是一种java容器了. 现在再看到Hash心底里有没有会心一笑呢,这里不再赘述hash的概念原理等一大堆东西了(不懂得需要先回去看下Has ...
- 关于set和map迭代器支持的运算
问题: 曾经想遍历一个set遍历.当时是这样写的: set<int>::iterator b = a.begin()+1 后来发现程序报错.究其原因是,set迭代器不支持加减数操作. 查看 ...
- Planning The Expedition(暴力枚举+map迭代器)
Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is t ...
- 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 ...
- Coins and Queries(map迭代器+贪心)
题意 n个硬币,q次询问.第二行给你n个硬币的面值(保证都是2的次幂!).每次询问组成b块钱,最少需要多少个硬币? Example Input 5 42 4 8 2 4851410 Output 1- ...
- vector map迭代器失效解决方案
vector : iter = container.erase(iter); //erase的返回值是删除元素下一个元素的迭代器 vector<int>::iterator it = ...
- Map迭代器
今天用到了,发现不会,随手谷歌之,整理如下. //Map是接口,刚才在那new Map,汗颜 Map<Character,Integer> mm = new HashMap ...
- 【c++】map 迭代器删除演示样例
C++ STL中的map是很常见的.通常我们用例如以下方式来遍历,而且删除map中的一些entry: map<int, int> mp; mp.insert(make_pair(1,1)) ...
- const 迭代器和 const_iterator (vector/set/map)
vector: 如同一般复合类型一样,vector 迭代器也可以声明成: const vector<int>::iterator it1 = v.begin(); vector<in ...
随机推荐
- iOS页面右滑返回的实现方法总结
1.边缘触发的系统方法 ①系统返回按钮 self.navigationController.interactivePopGestureRecognizer.enabled = YES; ②自定义返回 ...
- 关于Android中的四大组件(Service的开启与关闭)
前言 服务(Service)是Android系统中的四大组件之中的一个.服务主要用于两个目的:后台执行和跨进程訪问. 通过启动 一个服务.能够在不显示界面的前提下在后台执行指定的任务,这样能够不影响用 ...
- LeetCode 206. Reverse Linked List (倒转链表)
Reverse a singly linked list. 题目标签:Linked List 题目给了我们一个链表,要求我们倒转链表. 利用递归,新设一个newHead = null,每一轮 把下一个 ...
- 云上kafka和自建kafka对比
说起Kafka,许多使用者对它是又爱又恨.Kafka是一种分布式的.基于发布/订阅的消息系统,其极致体验让人欲罢不能,但操心的运维.复杂的安全策略.可靠性易用性的缺失.算不上极致的性能发挥.并不丰富的 ...
- 3.1 The Interpolating Polynomial(站点)
Cubic Interpolation: https://www.youtube.com/watch? v=EtzlEA9MIwI Quad ...
- session失效,使用ajax请求数据被拦截,此时正常的处理逻辑是跳到登录界面,而不是界面没有变化(java推断是否是ajax请求)
在登录过滤器中.推断请求是ajax请求还是超链接或者地址栏变化的请求 if (httpServletReq.getHeader("x-requested-with") != nul ...
- LLDB 常用命令
dump: memory read --force --outfile [文件名] --binary [start_address] [end_address] 查找函数地址: 对于有调试符号的这样使 ...
- javascript的call和apply
coffeescript里,每个文件编译成JS后,都是(function(){...}).call(this);的架势 这个call,该怎么理解呢? 在javascript里面,call 或者 app ...
- changing permissions of Read-only file system in linux
up vote 2 down vote favorite 1 i use this command to make a bootable flash disk of linux mint sudo ...
- YTU 2720: 删出多余的空格
2720: 删出多余的空格 时间限制: 1 Sec 内存限制: 128 MB 提交: 338 解决: 201 题目描述 小平在给弟弟检查英语作业时时,发现每个英语句子单词之间的空格个数不等,请你编 ...