Files
python/C++专题课程/STL基础知识/STL-6-map键值对.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

29 lines
810 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include<bits/stdc++.h>
using namespace std;
/*
知识点内容STL map详解
Map是STL的一个关联容器它提供一对一其中第一个可以称为关键字每个关键字只能在map中出现一次第二个可能称为该关键字的值的数据处理能力
由于这个特性,它完成有可能在我们处理一对一数据的时候,在编程上提供快速通道。
文档内容参考:
https://www.cnblogs.com/aiguona/p/7231451.html
* */
int main() {
map<char, int> a;//定义map函数
a.insert(map<char, int>::value_type('c', 1));//插入元素
a.insert(map<char, int>::value_type('d', 2));
map<char, int>::iterator b = a.find('c');//查找元素
map<char, int>::const_iterator it;
for (it = a.begin(); it != a.end(); ++it)
cout << it->first << "=" << it->second << endl;
cout << endl;
a.clear();//删除所有元素
return 0;
}