C++ STL 之哈希表 | unordered_map
#include <iostream>
#include <string>
#include <unordered_map>
int main(int argc, const char * argv[]) {
std::unordered_map<int, std::string> map;
map.insert(std::make_pair(1, "c++"));
map.insert(std::make_pair(22, "php"));
map.insert(std::make_pair(333, "dart"));
map.insert(std::make_pair(4444, "js"));
map.insert(std::make_pair(55555, "python"));
std::unordered_map<int, std::string>::iterator it;
if ( ( it = map.find(22) ) != map.end()) {
std::cout<< it->first << std::endl; //输出22
std::cout<< it->second << std::endl; //输出php
}
return 0;
}
本文标题:C++ STL 之哈希表 | unordered_map
本文链接:https://www.haomeiwen.com/subject/klzhcctx.html
网友评论