how to find element in unorder map c 2b 2b

Solutions on MaxInterview for how to find element in unorder map c 2b 2b by the best coders in the world

showing results for - "how to find element in unorder map c 2b 2b"
Nele
05 Nov 2018
1// unordered_map::find
2#include <iostream>
3#include <string>
4#include <unordered_map>
5
6int main ()
7{
8  std::unordered_map<std::string,double> mymap = {
9     {"mom",5.4},
10     {"dad",6.1},
11     {"bro",5.9} };
12
13  std::string input;
14  std::cout << "who? ";
15  getline (std::cin,input);
16
17  std::unordered_map<std::string,double>::const_iterator got = mymap.find (input);
18
19  if ( got == mymap.end() )
20    std::cout << "not found";
21  else
22    std::cout << got->first << " is " << got->second;
23
24  std::cout << std::endl;
25
26  return 0;
27}