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. 虚拟机无法上网的问题:无法启动VMnet0等问题

    虚拟机无法上网,由于之前安装过虚拟机,后来将它卸载了,然后重新安装,最后出现了虚拟机无法上网.刚开始以为是系统的原因,于是就通过linux命令查看系统里面的网卡时是否启动,如:/etc/init.d/ ...

  2. UIViewController添加子控制器(addChildViewController)

    // //  TaskHallViewController.m //  yybjproject // //  Created by bingjun on 15/10/27. //  Copyright ...

  3. Security Checklist (路由器安全checklist)

    Security Checklist Website by     Michael Horowitz  Home | Introduction | Router Bugs | Security Che ...

  4. Ubuntu 14.10 下awk命令详解

    简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再 ...

  5. ELF Spec

    ELF Spec Generic System V Application Binary Interface,ELF-64 Object File Format AMD64 System V ABI, ...

  6. HDU 5050

    http://acm.hdu.edu.cn/showproblem.php?pid=5050 大数gcd import java.io.* ; import java.math.* ; import ...

  7. Ztree实现带checkBox的下拉框

    UI <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ArticleMove ...

  8. Unity3d Shader

    Unity3d Shader 预览Surface Shader主要用来实现光照相关处理,可能更简洁. Vertex and Fragment Shader 如果不与光照交互, 则可以用这个shader ...

  9. LeetCode Sum Root to Leaf Numbers(DFS)

    题意: 给一棵二叉树,每个节点上有一个数字,范围是0-9,将从根到叶子的所有数字作为一个串,求所有串的和. 思路: 普通常规的DFS. /** * Definition for a binary tr ...

  10. Git 基础学习篇(应用-windows篇)

    此篇教程主要是讲应用,因为理论,,,额,我也说不出来.大家要深入学习还是看廖老师的教程吧. 可以把这篇当作一个简单应用的参考,因为当初看廖老师的也难看啊!!! 以下是资料: 廖雪峰-Git教程 [Gi ...