C++ 学习小程序之 map 的用法
1. map::at
#include <iostream>
#include <string>
#include <map>
using namespace std; int main(){
map<string, int> mymap = {
{"alpha", },
{"beta", },
{"gamma", }}; mymap.at("alpha") = ;
mymap.at("beta") = ;
mymap.at("gamma") = ; for (auto& x:mymap){
cout<<x.first<<": "<<x.second<<'\n';
} return ;
}
2. make_pair example
// make_pair example
#include <utility> // std::pair
#include <iostream> // std::cout int main () {
std::pair <int,int> foo;
std::pair <int,int> bar; foo = std::make_pair (,);
bar = std::make_pair (10.5,'A'); // ok: implicit conversion from pair<double,char> std::cout << "foo: " << foo.first << ", " << foo.second << '\n';
std::cout << "bar: " << bar.first << ", " << bar.second << '\n'; return ;
}
3. map::begin/end
// map::begin/end
#include <iostream>
#include <map> int main ()
{
std::map<char,int> mymap; mymap['b'] = ;
mymap['a'] = ;
mymap['c'] = ; // show content:
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
std::cout << it->first << " => " << it->second << '\n'; return ;
}
4. map::insert(C++98)
// map::insert(C++98)
#include <iostream>
#include <map>
using namespace std;
int main ()
{
map<char,int> mymap; // first insert function version (single parameter):
mymap.insert ( pair<char,int>('a', ) );
mymap.insert ( pair<char,int>('z', ) ); pair<map<char, int>::iterator, bool> ret;
ret = mymap.insert (pair<char,int>('z',));
if (ret.second == false){
cout<<"element 'z' already existed";
cout<<"with a value of " << ret.first->second << '\n';
} //second insert function version (with hint position):
map<char, int>::iterator it = mymap.begin();
mymap.insert (it, pair<char, int>('b',)); // max efficiency inserting
mymap.insert (it, pair<char, int>('c',)); // no max efficiency inserting //third insert function version (range insertion):
map<char,int> anothermap;
anothermap.insert(mymap.begin(),mymap.find('c')); // showing contents:
cout<<"mymap contains: \n";
for (it = mymap.begin(); it!= mymap.end(); ++it)
cout<<it->first<<"=>"<<it->second<<'\n'; cout<<"anothermap contains: \n";
for(it=anothermap.begin(); it!=anothermap.end();++it)
cout<<it->first<<"=>"<<it->second<<'\n'; return ;
}
C++ 学习小程序之 map 的用法的更多相关文章
- 跟我一起,利用bitcms内容管理系统从0到1学习小程序开发:一、IIS下SSL环境搭建
缘起 1.从事互联网十来年了,一直想把自己的从事开发过程遇到的问题给写出来,分享给大家.可是可是这只是个种想法,想想之后就放下了,写出来的类文章是少之又少.古人说无志之人常立志,有志之人立长志.今天, ...
- HotApp小程序统计云后台 免费的Https云后台服务器,方便学习小程序
小程序学习有些地方需要后台,比如需要存储数据到服务器,比如微信登录. hotapp有免费的小程序云后台 包含基本的 新增,查询,修改,删除 操作,方便于学习,而且不需要微信appid 也可使用. 小程 ...
- mpvue微信小程序多列选择器用法:实现省份城市选择
前言 微信小程序默认给我们提供了一个省市区的picker选择器,只需将mode设置为region即可 <picker mode="region" bindchange=&qu ...
- 小程序开发-11-Promise正确用法与函数签名设计技巧
配置taBar "tabBar": { "selectedColor": "#000000", "backgroundColor& ...
- 微信小程序之 map 地图使用
1.在app.json中与pages平级的位置处,加上: "permission": { "scope.userLocation": { "desc& ...
- 微信小程序_(map)简单的小地图
map地图效果 官方文档:传送门 Page({ data: { markers: [{ iconPath: "/resources/others.png", id: 0, lati ...
- 小程序开发-Map地图组件
Map组件 是原生组件,使用时请注意相关限制.个性化地图能力可在小程序后台"设置-开发者工具-腾讯位置服务"申请开通. 设置subkey后,小程序内的地图组件均会使用该底图效果,底 ...
- 小程序之map地图上不能在覆盖层
问题:页面上有一个地图功能,地图上面有两个按钮,是需要覆盖在地图上的,在小程序编辑器中显示是没问题的,但是扫码测试后发现在手机上不显示这两个按钮 解决方法:使用cover-viwe标签包裹一下就可以了
- 小程序地图map
wxml: <button class="button" bindtap="getlocation" style="margin-top:30p ...
随机推荐
- Cocoa Drawing
Graphics Contexts Graphics contexts are a fundamental part of the drawing infrastructure in Cocoa ap ...
- PAT 07-2 A+B和C
有两个值得注意的地方:1.变长数组(VLA)的使用,没想到PAT上的OJ竟然支持C99,一开始不知道就没用,看了看别人的,既然,还是用吧, 它有一点我不太喜欢,它不能像一般数组那样在声明时通过赋一个0 ...
- mysql 批量创建表,利用存储过程
最近根据需求,需要提前创建一批日志表,以日期结尾,每天创建一张,例如XXX20160530,请参考如下: BEGIN DECLARE `sName` VARCHAR(128); DECLAR ...
- hdu 2080
ps:水题...求夹角...先求出COS,然后用acos 代码: #include "stdio.h" #include "math.h" int main() ...
- UID 修改 & UID 锁死修复
首先是UID修改的问题,只要卡是UID卡,就都可以修改UID,首先读卡器连接电脑,卡片放到读卡器上. 然后我们要用一个工具,UID207.打开UID207.exe,点Initialize,初始化. 然 ...
- Python OpenCV ——Matplotlib显示图片
Color image loaded by OpenCV is in BGR mode.But Matplotlib displays in RGB mode.So color images will ...
- HDU 4986
http://acm.hdu.edu.cn/showproblem.php?pid=4986 题意:n个钥匙放在n个箱子里,每个钥匙和箱子一一对应,求打开所有箱子的期望 题解: 题意: 求随机排列的期 ...
- 著名的安装制作软件InnoSetup的源码及示例源码-The installation of a well-known software s source code and sample InnoSetup source
@echo off rem Inno Setup rem Copyright (C) 1997-2007 Jordan Russell rem Portions by Martijn Laan rem ...
- Magento请求分发与控制器
Magento请求分发与控制器 Magento使用的是MVC结构,模型-试图-控制器结构,这样更好的实现显示逻辑和数据,业务逻辑的分离,更好的适合开发! 下面为传统的mvc结构 URL请求被一个PHP ...
- 用vs2008打开vs2012项目
1 使用记事本打开*.sln解决方案文件,将Visual Studio 2012改为Visual Studio 2008 将版本号改为9.00 2 打开扩展名为*.csproj的项目文件,修改为 To ...