-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathiteratorHashmap.cpp
More file actions
42 lines (35 loc) Β· 852 Bytes
/
iteratorHashmap.cpp
File metadata and controls
42 lines (35 loc) Β· 852 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
#include<iostream>
#include<unordered_map>
#include<string>
#include<vector>
using namespace std;
int main()
{
unordered_map<string,int> ourmap;
ourmap["abc"]=1;
ourmap["abc1"]=2;
ourmap["abc2"]=3;
ourmap["abc3"]=4;
ourmap["abc4"]=5;
ourmap["abc5"]=6;
//syntax of iterator in unordered map;
unordered_map<string,int>::iterator it=ourmap.begin(); //it is a pointer which is pointing to ourmap.begin()
while(it!=ourmap.end())
{
cout<<"key : "<<it->first<<" value: "<<it->second<<endl;
it++;
}
//syntax of iterator of vector;
vector<int>v;
v.push_back(10);
v.push_back(9);
v.push_back(8);
v.push_back(7);
v.push_back(6);
vector<int>::iterator it1=v.begin();
while(it1!=v.end())
{
cout<<*it1<<endl;
it1++;
}
}