【STL】-Map/Multimap的用法
初始化:
map<string,double> salaries;
算法:
1. 赋值。salaries[ "Pat" ] = 75000.00;
2. 无效的索引将自动添加一项
cout << salaries[ "Jan" ] << endl;
3. Map的第一个或者第二个元素为数组的情况
代码:
#include <map>
#include <string>
#include <iostream>
using namespace std; int main( )
{
map<string,double> salaries; salaries[ "Pat" ] = 75000.00;
cout << salaries[ "Pat" ] << endl;
cout << salaries[ "Jan" ] << endl; map<string,double>::const_iterator itr;
itr = salaries.find( "Jan" );
if( itr == salaries.end( ) )
cout << "Not an employee of this company!" << endl;
else
cout << itr->second << endl; return ;
}
输出:
$ ./a.exe
【STL】-Map/Multimap的用法的更多相关文章
- STL——map/unordered_map基础用法
map /multimap map是STL里重要容器之一. 它的特性总结来讲就是:所有元素都会根据元素的键值key自动排序(也可根据自定义的仿函数进行自定义排序),其中的每个元素都是<key, ...
- 2.9 C++STL map/multimap容器详解
文章目录 2.9.1 引入 2.9.2 代码示例 map案列 multimap案列 2.9.3 代码运行结果 总结 2.9.1 引入 map相对于set区别,map具有键值和实值,所有元素根据键值自动 ...
- STL::map/multimap
map: 默认根据 key 排序(从小到大),能够通过 backet operator(operator [ ]) 来获取元素,内部由二叉搜索树来实现(binary search trees). mu ...
- stl map一对多用法
// stlMap.cpp : Defines the entry point for the console application.//#pragma warning (disable : 478 ...
- STL:map/multimap用法详解
map/multimap 使用map/multimap之前要加入头文件#include<map>,map和multimap将key/value当作元素,进行管理.它们可根据key的排序准则 ...
- STL之六:map/multimap用法详解
转载于:http://blog.csdn.net/longshengguoji/article/details/8547007 map/multimap 使用map/multimap之前要加入头文件# ...
- STL map 用法
首先make_pair Pairs C++标准程序库中凡是"必须返回两个值"的函数, 也都会利用pair对象 class pair可以将两个值视为一个单元.容器类别map和mul ...
- STL Map和multimap 容器
STL Map和multimap 容器 map/multimap的简介 map是标准的关联式容器,一个map是一个键值对序列,即(key,value)对.它提供 基于key的快速检索能力. ...
- STL之map&multimap使用简介
map 1.insert 第一种:用insert函数插入pair数据 #include <map> #include <string> #include <iostrea ...
随机推荐
- js 的小效果---->选项卡
js选项卡 <!doctype html> <html> <head> <meta charset="utf-8"> <t ...
- Gas Station
Description: There are N gas stations along a circular route, where the amount of gas at station i i ...
- jackson反序列化时忽略不需要的字段(zhuan)
http://www.cnblogs.com/davidwang456/p/5434071.html ********************************************* 有时候 ...
- J2EE 第二阶段项目(八)
类别统计差不多完成了! 还有个地区统计了!
- jQuery中其他
hide: 隐藏 $('img').hide(); show:显示 $('img').show(); 单选多选下拉菜单 选中状态checked ($('.radio:checked')); 单选 ( ...
- VB6 GDI+ 入门教程[3] 笔、刷子、矩形、椭圆绘制
http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[3] 笔.刷子.矩形.椭圆绘制 2009 年 6 月 1 ...
- java 集合2(迭代器)
迭代器方法:(把迭代器想象成抓娃娃机的爪子) hasNext() 问是否有元素可遍历,如果有元素可以遍历,返回true,否则返回false 工作原理:这一个迭代的过程是这样的,获取到迭代器时候 ...
- java视频格式转换代码
http://blog.163.com/zzf_fly/blog/static/20958915820127217443816/ package com.gkzx.online.action; imp ...
- linux笔记:linux常用命令-链接命令
文件处理命令:ln(创建链接文件) ln -s 源文件 链接文件 需要源文件已经建立,执行链接文件就是执行源文件. 软链接文件的特点: 1.类似于windows中快捷方式的作用: 2.它的文件类型是 ...
- 【BZOJ 2243】染色 - 树链剖分+线段树
#include <cstdio> #include <cstring> #include <cstdlib> using namespace std; const ...