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 的用法的更多相关文章

  1. 跟我一起,利用bitcms内容管理系统从0到1学习小程序开发:一、IIS下SSL环境搭建

    缘起 1.从事互联网十来年了,一直想把自己的从事开发过程遇到的问题给写出来,分享给大家.可是可是这只是个种想法,想想之后就放下了,写出来的类文章是少之又少.古人说无志之人常立志,有志之人立长志.今天, ...

  2. HotApp小程序统计云后台 免费的Https云后台服务器,方便学习小程序

    小程序学习有些地方需要后台,比如需要存储数据到服务器,比如微信登录. hotapp有免费的小程序云后台 包含基本的 新增,查询,修改,删除 操作,方便于学习,而且不需要微信appid 也可使用. 小程 ...

  3. mpvue微信小程序多列选择器用法:实现省份城市选择

    前言 微信小程序默认给我们提供了一个省市区的picker选择器,只需将mode设置为region即可 <picker mode="region" bindchange=&qu ...

  4. 小程序开发-11-Promise正确用法与函数签名设计技巧

    配置taBar "tabBar": { "selectedColor": "#000000", "backgroundColor& ...

  5. 微信小程序之 map 地图使用

    1.在app.json中与pages平级的位置处,加上: "permission": { "scope.userLocation": { "desc& ...

  6. 微信小程序_(map)简单的小地图

    map地图效果 官方文档:传送门 Page({ data: { markers: [{ iconPath: "/resources/others.png", id: 0, lati ...

  7. 小程序开发-Map地图组件

    Map组件 是原生组件,使用时请注意相关限制.个性化地图能力可在小程序后台"设置-开发者工具-腾讯位置服务"申请开通. 设置subkey后,小程序内的地图组件均会使用该底图效果,底 ...

  8. 小程序之map地图上不能在覆盖层

    问题:页面上有一个地图功能,地图上面有两个按钮,是需要覆盖在地图上的,在小程序编辑器中显示是没问题的,但是扫码测试后发现在手机上不显示这两个按钮 解决方法:使用cover-viwe标签包裹一下就可以了

  9. 小程序地图map

    wxml: <button class="button" bindtap="getlocation" style="margin-top:30p ...

随机推荐

  1. acm 20140825

    为了自己的梦想,一次次的选择坚强.走上acm这条路,怎么也找不到让自己放弃的理由.我喜欢这种竞赛的氛围,我渴望在赛场上飞扬!想想过去的一个学习,自己并没有干点什么有意义的事.acm也没有好好的做!新的 ...

  2. SQLSERVER数据库中批量导入数据的几种方法

    第一:使用Select Into 语句 如果企业数据库都是采用SQL Server数据库的话,则可以利用select into语句实现数据的导入. select into语句的作用是把数据从另外一个数 ...

  3. 重拾java系列一java基础(4)

    本章主要回顾一些类的相关知识: (1)static: static 静态的: 属于类的资源, 使用类名访问.  静态属性: 只有一份的变量  静态方法: 是属于类方法, 可以使用类名直接访问. 静态方 ...

  4. postgreSQL9.1忘记postgres用户密码怎么办

    在网络上找了一篇文章http://www.linuxidc.com/Linux/2010-04/25232.htm,如下: Ubuntu 9.10下PostgreSQL 8.4忘记密码的解决方法 Ub ...

  5. 多比Web 3D展示(3D机房/3D监控)中间件多比Web 3D展示(3D机房/3D监控)中间件免费下载购买地址

    多比3D是实现3D场景搭建的软件开发包,可以创建广泛的3D应用,适用于高端制造.能源.国防军工.教育科研.城市规划及建筑环艺.生物医学等领域的虚拟仿真,应用于虚拟展示.虚拟设计.方案评审.虚拟装配.虚 ...

  6. php大力力 [018节]如何联系大力力

    有事儿就注册博客园,给我发 博客园站内的 短消息呗,唉,没有人联系我呀,啦啦啦,爱我爱我,快点爱我 2015-08-26 php大力力018.如何联系大力力

  7. ERP系统上传文档信息下载(十八)

    下载的公用方法: /// <summary> /// 下载文档 /// </summary> /// <param name="TableName"& ...

  8. 怎样修改Response中的内容

    重写Stream public class CatchTextStream : Stream { private Stream output; public CatchTextStream(Strea ...

  9. inno setup教程解释脚本

    inno setup教程解释脚本 2007-04-08 21:31:36|  分类: 科技-> Inno Setu |  标签:inno   |举报 |字号 订阅     下载LOFTER客户端 ...

  10. 使用SSMS 2014将本地数据库迁移到Azure SQL Database

    使用SQL Server Management Studio 2014将本地数据库迁移到Azure SQL Database的过程比较简单,在SSMS2014中,有一个任务选项为“将数据库部署到Win ...