I want to create a simple data storage using map,
map<int , Person> people;
where Person is
class Person
{
string name;
int age;
public:
Person() : name("noname"), age(0) {}
Person(string name, int age) : name(name), age(age) {}
void print()
{
cout << "| " << name << " | " << age << endl;
}
};
and I have a problem with referring to people.name in map::find() function. Probably I just don't know the correct syntax and I can't find the answer. It probably should look something like that, but name is the element of Person class so I guess it should give me an error.
if (people.find(name) != people.end())
{
people.erase(name);
cout << name << " removed from data base" << endl;
}
else
{
cout << name << " not found" << endl;
}
Sorry for my ignorance, but I started programming quite recently, that's why i don't know basic syntax and get confused sometimes.