c++ map
STL map基本使用
hash_map 基本使用
STL map基本使用
头文件
#include <map>
//自定义排序
class MySortMap {
public:
bool operator()(int v1,int v2) const {
return v1>v2;
}
};
void test01()
{
map<int,int> m; //map<int,int,MySortMap> xxx;
//第一种
m.insert(pair<int, int>(1, 10));
//第二种 推荐
m.insert(make_pair(2, 20));
//第三种
m.insert(map<int, int>::value_type(3, 30));
//第四种
m[4] = 40;
for (auto it = m.begin(); it != m.end(); ++it)
cout << "key = " << it->first << " val = " << it->second << endl;
}
hash_map 基本使用
头文件`#include <ext/hash_map>
typedef __gnu_cxx::hash_map<int,Io_buf*> hash_map;
[hash_map 详细介绍]https://blog.csdn.net/yousss/article/details/79541543
浙公网安备 33010602011771号