map data access by key in cpp

Solutions on MaxInterview for map data access by key in cpp by the best coders in the world

showing results for - "map data access by key in cpp"
Beatrice
12 Jul 2019
1// accessing mapped values
2#include <iostream>
3#include <map>
4#include <string>
5
6int main ()
7{
8  std::map<char,std::string> mymap;
9
10  mymap['a']="an element";
11  mymap['b']="another element";
12  mymap['c']=mymap['b'];
13
14  std::cout << "mymap['a'] is " << mymap['a'] << '\n';
15  std::cout << "mymap['b'] is " << mymap['b'] << '\n';
16  std::cout << "mymap['c'] is " << mymap['c'] << '\n';
17  std::cout << "mymap['d'] is " << mymap['d'] << '\n';
18
19  std::cout << "mymap now contains " << mymap.size() << " elements.\n";
20
21  return 0;
22}