Is there a better or more appropriate way to do this the “STL way”?
You can use std::find_if
(powered by C++11 lambdas):
std::string name = "Bob";
// ...
std::find_if(std::begin(people), std::end(people),
[&] (Person const& p) { return p.Name == name; }
Notice, that calling it "STL way" is inappropriate. This is the C++ Standard Library, not the STL ("Standard Template Library"). The STL served as a strong inspiration for the Containers and Algorithms Library of the C++ Standard Library, but the two things are not the same. See this Q&A on StackOverflow for further information.
EDIT:
Since you are using a compiler that does not support lambdas, you can define your own functor predicate:
struct person_has_name
{
person_has_name(std::string const& n) : name(n) { }
bool operator () (Person const& p) { return p.Name == name; }
private:
std::string name;
};
And use it with std::find_if
this way:
std::string name = "Bob";
// ...
std::find_if(people.begin(), people.end(), person_has_name(name));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…