unordered_map
作者:Lew's Personal Blog 发布于:2020-3-24 14:56 Tuesday 分类:C/C++
#include <iostream>
#include <string>
#include <unordered_map>
int main(int argc, char** argv)
{
std::unordered_map<std::string,double> mymap = {
{"mom",5.4},
{"dad",6.1},
{"bro",5.9}
};
std::string input;
std::cout << "who? ";
getline (std::cin,input); //注意
std::unordered_map<std::string,double>::const_iterator got = mymap.find (input);
if ( got == mymap.end() )
std::cout << "not found";
else
std::cout << got->first << " is " << got->second;
std::cout << std::endl;
getchar();
return 0;
}
标签: unordered_map
« 上一篇 单链表的排序,时间复杂度为O(nlogn) | 二叉树搜索树基本操作 下一篇»