-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap0.cpp
More file actions
44 lines (36 loc) · 867 Bytes
/
map0.cpp
File metadata and controls
44 lines (36 loc) · 867 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
40
41
42
43
44
#include <map>
#include <iostream>
#include <algorithm>
using std::map;
using std::cout;
using std::endl;
using std::pair;
using std::string;
void PrintEntry(const pair <string, int> &e)
{
cout << e.first << ' ' << e.second << endl;
}
int main(void)
{
map <string, int> PhoneBook
{
{ "Ivan", 11111 },
{ "Petr", 22222 },
{ "Vasily", 33333 },
{ "Dmitry", 44444 },
{ "Alexey", 55555 }
};
for(const auto &x: PhoneBook)
cout << x.first << ' ' << PhoneBook[x.first] << endl;
cout << endl;
PhoneBook["Paramon"] = 66666;
const pair <string, int> p { "Filaret", 77777 };
PhoneBook.insert(p);
PhoneBook.insert({"Filimon", 88888});
PhoneBook.emplace("Akaky", 99999);
for(const auto &x: PhoneBook)
cout << x.first << ' ' << PhoneBook[x.first] << endl;
cout << endl;
for_each(PhoneBook.cbegin(), PhoneBook.cend(), PrintEntry);
return int();
}