美文网首页
C++ STL 之哈希表 | unordered_map

C++ STL 之哈希表 | unordered_map

作者: 设置一个看起来合理的昵称 | 来源:发表于2019-06-26 21:53 被阅读0次
#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