I don’t know how to print a returned value of a custom object
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <string>
class Person{
public:
string name;
int age;
Person(string name, int age){
this->name = name;
this->age = age;
}
};
class listOfPeople{
private:
vector <Person> myList ;
public:
void fillTheList(Person p){
myList.push_back(p)
}
Person findPerson(string name){
for(Person p : myList){
if(strcasecmp(p.name.c_str(), name.c_str()) == 0){
return p; // returns a person
}
}
return {};
}
};
int main(){
Person p1("Vitalik Buterin", 30);
Person p2("Elon musk", 50);
ListOfPeople L;
L.fillTheList(p1);
L.fillTheList(p2);
Person p = L.findPerson("Vitalik"); // I don't know what to do here( I want to print Vitalik's information, the full name and age)
return o;
}
I don’t know how to print the informations of the returned value. I hope my question is clear. I
tried different things but can’t get the right logic
>Solution :
you just need
std::cout << p.name << " is " << p.age <<'/n';