How to insert objects in map c++
Sep 12, 2016 at 4:33pm UTC
I don't know how to insert my objects in map.I know how to introduce items in the list , but not in the map . If someone can help me, please, I will be very happy :D.
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
#include<iostream>
#include<map>
using namespace std;
class Student{
public :
Student(string n="" ,int a=0)
{
name=n;
age=a;
}
void show()
{
cout<<"Name: " <<name<<" age:" <<age<<endl;
}
private :
int age;
string name;
};
int main()
{
Student d1("Flaviu" ,20);
Student d2("Dezibil" ,35);
Student d3("Etc" ,69);
map<int ,Student>myMap;
}
Sep 12, 2016 at 4:48pm UTC
Topic archived. No new replies allowed.