当前位置:网站首页>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更快。
边栏推荐
- IQ debugging of Hisilicon platform ISP and image (1)
- The "&" character will destroy the data stored in the web The "&" character breaks passwords that are stored in the web config
- Guess the size of the number
- Analysis report on production and sales demand and sales prospect of global and Chinese phosphating solution Market 2022-2028
- Kotlin reflection -- Notes
- Sword finger offer II 095 Longest common subsequence
- Curl command – file transfer tool
- General test point ideas are summarized and shared, which can be directly used in interview and actual software testing
- PHP output (print) log to TXT text
- Advantages and disadvantages of using SNMP and WMI polling
猜你喜欢
Uni app wechat applet customer service chat function
@Detailed explanation of valid annotation usage
ARM processor operating mode
[data visualization application] draw spatial map (with R language code)
2022 AI trend 8 forecast!
The five minute demonstration "teaches" actors to speak foreign languages and can seamlessly switch languages. This AI dubbing company has just received a round a financing of 20million US dollars
[short time average zero crossing rate] short time average zero crossing rate of speech signal based on MATLAB [including Matlab source code 1721]
Introduction to sap ui5 tools
Understand what ICMP Protocol is
[Suanli network] problems and challenges faced by the development of Suanli network
随机推荐
2022-02-19: fence installation. In a two-dimensional garden, there are some trees represented by (x, y) coordinates. As the installation cost is very expensive, your task is to enclose all the trees w
Global and Chinese gallium nitride (GAN) market output value scale forecast and application prospect analysis report 2022
SAP QM executes the transaction code qp01, and the system reports an error -material type food is not defined for task list type Q-
Viewing Chinese science and technology from the Winter Olympics (V): the Internet of things
[200 opencv routines of youcans] 104 Motion blur degradation model
At the age of 26, I was transferred to software testing with zero foundation. Now I have successfully entered the job with a monthly salary of 12K. However, no one understands my bitterness
Vegetables sklearn - xgboost (2)
Global and Chinese kaolin market operation scale and investment development proposal report 2022
JD 8 fleet stores search history, deletes history, clears history (not finished)
How two hosts in different network segments directly connected communicate
Understand what MTU is
Observation configuring wmic
What does cardinality mean in set
Analysis report on demand scale and Supply Prospect of global and Chinese thermal insulation materials market during the 14th Five Year Plan period 2022-2028
Explain @builder usage
[network security] sharing of experience and ideas of an emergency battle
ARM processor operating mode
VMware virtual machine prompt: the virtual device ide1:0 cannot be connected because there is no corresponding device on the host.
Arm register (cortex-a), coprocessor and pipeline
Preliminary practice of niuke.com (summary)