-
Notifications
You must be signed in to change notification settings - Fork 0
/
howToUseMap.cpp
32 lines (27 loc) · 1.03 KB
/
howToUseMap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <unordered_map>
#include <string>
#include <iostream>
using namespace std;
int main(){
unordered_map<int,string > wordMap;
wordMap.insert({123456,"Visa"});
wordMap.insert({456789,"MasterCard"});
wordMap.insert({799456,"Maestro"});
unordered_map<int,string >::const_iterator iter = wordMap.find(123456);
if ( iter == wordMap.end() )
std::cout << "not found";
else
std::cout << iter->first << " is " << iter->second ;
std::cout << endl;
// unordered_map<int, pair<string,string> > wordMap;
// wordMap.insert({ 123456, make_pair("Visa", "Credit")});
// wordMap.insert({ 456789, make_pair("MasterCard", "Credit")});
// wordMap.insert({ 799456, make_pair("Maestro", "Credit")});
// unordered_map<int, pair<string,string> >::const_iterator iter = wordMap.find(123456);
// if ( iter == wordMap.end() )
// cout << "not found";
// else
// cout << endl;
// cout << iter->first << " is " << iter->second.first << ","<< iter->second.second;
return 0;
}