std::map用法
STL是标准C++系统的一组模板类,使用STL模板类最大的好处就是在各种C++编译器上都通用。
UDT_MAP_INT_CSTRING enumMap;
enumMap[2] = "Two";
.....
enumMap[1] = "One Edit";
UDT_MAP_INT_CSTRING::iterator it; //定义一个条目变量(实际是指针)
it = enumMap.find(nFindKey);
if(it == enumMap.end()) {
//没找到
}
else {
//找到
}
iterator erase(iterator first, iterator last);
size_type erase(const Key& key);
enumMap.erase(enumMap.begin()); //删掉第一个条目
enumMap.erase(enumMap.begin(), enumMap.begin() + 1); //删掉起始的两个条目
#include<string>
#include<iostream>
using namespace std;
int main()
{
map<string,int> m;
m["a"]=1;
m["b"]=2;
m["c"]=3;
map<string,int>::iterator it;
for(it=m.begin();it!=m.end();++it)
cout<<"key: "<<it->first <<" value: "<<it->second<<endl;
return 0;
}
std::map用法的更多相关文章
- C++ std::map用法简介
#include "map" //引入头文件 初始化: std::map <int, std::string> _map1; //初始化 //c++11中引入的,可以直 ...
- C++ std::map::erase用法及其陷阱
1.引入: STL的map中有一个erase方法用来从一个map中删除制定的节点 eg: map<string,string> mapTest; typedef map<string ...
- UVA11995【I can guess the data structrue!!】【水】+UVA11991【map用法】
先看UVA11995 两份代码一份直接用C写的,一份用STL写的 #include <iostream> #include <stdio.h> #include <str ...
- C++中的STL中map用法详解
Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据 处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时 ...
- STL之std::set、std::map的lower_bound和upper_bound函数使用说明
由于在使用std::map时感觉lower_bound和upper_bound函数了解不多,这里整理并记录下相关用法及功能. STL的map.multimap.set.multiset都有三个比较特殊 ...
- sort函数(cmp)、map用法---------------Tju_Oj_2312Help Me with the Game
这道题里主要学习了sort函数.sort的cmp函数写法.C++的map用法(其实和数组一样) Your task is to read a picture of a chessboard posit ...
- C++中的STL中map用法详解(转)
原文地址: https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html C++中的STL中map用法详解 Map是STL的一个关联容器,它提供 ...
- C++:map用法及元素的默认值
C++:map用法 一.map基本用法 键值对 第一个参数为键的类型,第二个参数为值的类型. 源代码 #include <iostream> #include <string> ...
- C++ std::map
std::map template < class Key, // map::key_type class T, // map::mapped_type class Compare = less ...
随机推荐
- 课程设计 --- 黑白棋中的 AI
原文链接:https://www.dreamwings.cn/reversi/3013.html 到了考试周了佯,可是偏偏这个时候迎来了很多很多的课程设计,幸好教授把C语言的课程设计提前发出了,不然都 ...
- javascirpt对象运用与JS变量
abcdefghijklmnopqrstuvwyz String 对象方法 charAt() 方法可返回指定位置的字符.stringObject.charAt(index)(index从0开始)[ht ...
- linux 调用java main方法
#!/bin/shexport LANG=zh_CNtimestamp=`date +%Y%m%d%H%M`/opt/java6/bin/java -Xms128m -Xmx512m -Dfile.e ...
- jQuery 弹出层脚本
直接贴代码: $.extend({ closeBox: function (o, x, fn) { $('#' + o).fadeOut(500, function () { if (fn & ...
- Redhat、CentOS添加静态路由的标准方法
我们经常遇到需要在系统默认路由的基础上,额外添加静态路由的需求.为了使得下次系统启动这些静态路由依旧生效,我们可能采取在rc.loal里加入route命令追加静态路由的方法. 现在给大家推荐Redha ...
- 今天谈谈流,什么是IO流?
无标题 (5) :first-child { margin-top: 0; } blockquote > :last-child { margin-bottom: 0; } img { bord ...
- maven添加sqlserver的jdbc驱动包
http://search.maven.org/中没有sqlserver的jdbc驱动,所以需要本地安装sqljdbc的jar包,然后再在pom里面引入 Step 1 在微软官网下载sqljdbc的j ...
- ubuntu host备份 ubuntu无法解析主机
/etc/hosts # Copyright (c) 2014-2016, racaljk.# https://github.com/racaljk/hosts# Last updated: 2016 ...
- MyEclipse10安装Svn插件的几种方法
http://blog.sina.com.cn/s/blog_4f925fc30102e9xe.html 方法一:直接解压 下载SVN插件:site-1.6.18.zip 解压后将其全部文件拷贝至:D ...
- 从C++到GO
从C++到GO 刚开始接触Go语言,看了两本Go语言的书,从c++开发者的角度来看看go语言的新特性,说下自己感触较深的几点: 并发编程 Go语言层面支持协程,将并发业务逻辑从异步转为同步,大幅提高开 ...