当前位置:网站首页>STL map的用法
STL map的用法
2022-06-25 06:32:00 【雨中纸鸢943】
map就是映射,可以将任意基本类型映射到其他任意基本类型。
map的几个特性,里面的键值是唯一的,如果有重复就会覆盖前一个。
而且如果遍历访问的话,容器里面会自动实现从小到大的排序的。
目录
1.map定义
map<typename 1, typename 2> mp;
前面为建key,后面为值value。
2.map容器内元素的访问
(1).通过下标,将key作为下标。
(2).通过迭代器 map<typename 1, typename 2>::iterator it;
这样就可以得到迭代器it.
然后使用it->first 访问键,it->second 访问值。
3.map常用的函数的解析
(1) find(key),直接返回键值为key的映射的迭代器 如果找不到返回end().
(2) erase()
里面可以是迭代器,也可以是键,也可以是一个区间。
(3) size() 返回的是map映射的对数。
(4) clear()清空map中所有元素
(5) count(),可以计算一个键值出现的次数,因此可以用来判断是否存在一个键。
4.延申
可以用unordered_map来替代map,用散列来代替map内部的红黑树实现,但是牺牲了排序功能,速度会比map更快。
边栏推荐
- Lesson 9: workspace introduction
- Meta universe is over, Web 3.0 will be fooled again?
- We cannot activate inspection type for article master in transaction code MM41?
- [Suanli network] technological innovation of Suanli Network -- Key Technologies of green and security
- Copying DNA
- PHP output (print) log to TXT text
- Analysis report on production and sales demand and sales prospect of global and Chinese phosphating solution Market 2022-2028
- The elephant turns around and starts the whole body. Ali pushes Maoxiang not only to Jingdong
- PHP and WMI – explore windows with PHP
- [kicad image] download and installation
猜你喜欢
![[kicad image] download and installation](/img/88/cebf8cc55cb8904c91f9096312859a.jpg)
[kicad image] download and installation

General test point ideas are summarized and shared, which can be directly used in interview and actual software testing

3-7sql injection website instance step 3: attack type and attack strategy

Understand what MTU is

Exercise: completion

@Detailed explanation of valid annotation usage

Lesson 9: workspace introduction

2022 AI trend 8 forecast!

ARM processor operating mode
![[data visualization application] draw spatial map (with R language code)](/img/2d/04e5015573d10bdd6325ae497bfeb3.jpg)
[data visualization application] draw spatial map (with R language code)
随机推荐
VMware virtual machine prompt: the virtual device ide1:0 cannot be connected because there is no corresponding device on the host.
Brief introduction and use of JSON
Understand what MSS is
Digitalization, transformation?
[hand torn STL] Stack & queue
[Suanli network] problems and challenges faced by the development of Suanli network
[Suanli network] technological innovation of Suanli Network -- Key Technologies of green and security
Drosophila played VR and entered nature. It was found that there were attention mechanisms and working memory. The insect brain was no worse than that of mammals
Aviator an expression evaluation engine
Gb28181 protocol -- timing
[speech discrimination] discrimination of speech signals based on MATLAB double threshold method [including Matlab source code 1720]
What is VLAN
Is the number of indexes in a table the more the better?
Introduction to sap ui5 tools
A + B Again
Cannot activate inspection type when SAP retail uses transaction code mm41 to create commodity master data?
How to chain multiple different InputStreams into one InputStream
PHP output (print) log to TXT text
Is it safe to open a stock account on the Internet in Beijing?
Methods for obtaining some information of equipment