fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. class Person
  8. {
  9. string first;
  10. string last;
  11. int age;
  12.  
  13. public:
  14. Person(string first_name, string last_name, int the_age);
  15.  
  16. string getFirstName() const { return first; }
  17. string getLastName() const { return last; }
  18. int getAge() const { return age; }
  19. };
  20.  
  21. Person::Person(string first_name, string last_name, int the_age){
  22. first = first_name;
  23. last = last_name;
  24. age = the_age;
  25. }
  26.  
  27. int main()
  28. {
  29. vector<Person> people;
  30. people.emplace_back("Joe", "Smoe", 25);
  31. people.emplace_back("John", "Cool-Johnson", 15);
  32. people.emplace_back("Paul", "Bob", 1000);
  33.  
  34. auto max_name = max_element(
  35. people.begin(), people.end(),
  36. [](const Person &a, const Person &b){
  37. return a.getFirstName().size() < b.getFirstName().size();
  38. }
  39. )->getFirstName().size();
  40.  
  41. cout << max_name;
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
4