-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapClass.cpp
More file actions
43 lines (38 loc) · 922 Bytes
/
Copy pathmapClass.cpp
File metadata and controls
43 lines (38 loc) · 922 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
//map class : associative array
/*
size ,empty ,insert ,clear methods of map class
*/
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <map>
using namespace std;
int main()
{
system("cls");
//creating a map object key value pair
map <int,string>student;
student[1]="rohit";
student[2] = "rahul";
student[3] = "ruby";
student[4] = "sonam";
student[5] = "shahid";
map <string,string> course{
{"python","2 months"},
{"C++","3 months"},
{"java","3 months"}
};
//printing
cout<<"Studen roll 3 "<<student[3]<<endl;
//printing value using iterator
map <int,string>::iterator p = student.begin();
while(p != student.end())
{
cout<<p->first<<endl; //this is for index
cout<<p->second<<endl; //this is for value
p++;
}
//at function
cout<<student.at(4)<<endl;;
system("pause");
}