-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasics.cpp
45 lines (33 loc) · 875 Bytes
/
Basics.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
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* \file
* \brief
*
* \todo
*/
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
map<string, int> mapOfWords;
mapOfWords.insert(make_pair("earth", 1));
mapOfWords.insert(make_pair("moon", 2));
mapOfWords["sun"] = 3;
mapOfWords["earth"] = 4;
map<string, int>::iterator it = mapOfWords.begin();
while(it != mapOfWords.end())
{
cout << it->first << " :: " << it->second << endl;
it++;
}
//check if insertion is successfull
if (mapOfWords.insert(make_pair("earth", 1)).second == false)
cout << "Element with key 'earth' was not inserted as it already existed" << endl;
//Searching element in map by Key
if (mapOfWords.find("sun") != mapOfWords.end())
cout << "Word 'sun' was found" << endl;
if (mapOfWords.find("mars") == mapOfWords.end())
cout << "Word 'mars' was not found" << endl;
return 0;
}