VC++ 2010
Lets say I have the following:
struct person {
char * name;
int age;
};
Then I have a vector which holds these:
std::vector <person> person_list;
Now, after pushing back a few of these elements, how can I locate one based off of one of its properties? Best case scenario, I would like it to return a pointer to the vectors element 'where name = string' type of deal.
One suggestion to improve. Use
std::stringinstead ofchar*. You have to#include <string>for that.In C++11 you can use lamda and
std::find_ifas:In C++03, you can use functor as predicate: