Aug 25, 2019 at 3:01pm Aug 25, 2019 at 3:01pm UTC
Hi
A vector contains a few object, in those objects a certain member type is age which is a number. How to find the max age from the vector of objects using max_element algorithm.
How to write a lambda expression to get max date
Aug 25, 2019 at 3:10pm Aug 25, 2019 at 3:10pm UTC
Something like this.
1 2 3 4
auto iterator_to_max_age_element = std::max_element(theVector.begin(), theVector.end(),
[] (Object const lhs, Object const rhs) {
return lhs.age < rhs.age; });
cout << "Max age is " << (*iterator_to_max_age_element).age;
Chane it for your variable names, and the names of member variables etc
Last edited on Aug 25, 2019 at 3:10pm Aug 25, 2019 at 3:10pm UTC