-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaps.cpp
More file actions
39 lines (28 loc) · 828 Bytes
/
Maps.cpp
File metadata and controls
39 lines (28 loc) · 828 Bytes
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
33
34
35
36
37
38
39
#include "stdafx.h"
#include <iostream>
#include <map>
#include <string>
using namespace std;
int _main5(int argc, _TCHAR* argv[]) {
map<string, int> ages;
ages["Mike"] = 40;
ages["Raj"] = 20;
ages["Vicky"] = 30;
ages["Mike"] = 70;
//ages.insert(pair<string, int>("Peter", 100));
ages.insert(make_pair("Peter", 100));
cout << ages["Raj"] << endl;
if(ages.find("Vicky") != ages.end()) {
cout << "Found Vicky" << endl;
} else {
cout << "Key not found" << endl;
}
for(map<string, int>::iterator it = ages.begin(); it != ages.end(); it++) {
pair<string, int> age = *it;
cout << age.first << ": " << age.second <<endl;
}
for(map<string, int>::iterator it = ages.begin(); it != ages.end(); it++) {
cout << it->first << ": " << it->second <<endl;
}
return 0;
}