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 44 45 46 47 48 49
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class Person
{
public:
Person(const string& name, const string& address, int age):
mName(name), mAddress(address), mAge(age)
{}
const string& getName()const {return mName;}
const string& getAddress() const {return mName;}
int getAge() const {return mAge;}
private:
string mName;
string mAddress;
int mAge;
};
int main()
{
vector<Person> people =
{
Person("Anne", "some address", 22),
Person("Lisa", "some address", 33),
Person("Anja", "some address", 44)
};
string name;
cout << "Enter name of person to find: ";
getline(cin, name);
auto it = find_if(people.begin(), people.end(),
[&name](const Person& p)
{
return name == p.getName();
});
if (it != people.end()) // found
{
cout << "found";
}
else
{
cout << "not found";
}
}
|