how to sort vector of struct in c++
include
include
include
struct Person { std::string name; int age; };
bool comparePersons(const Person &a, const Person &b) { return a.age < b.age; }
int main() {
std::vector
std::sort(people.begin(), people.end(), comparePersons);
for (const auto &person : people) { std::cout << person.name << " " << person.age << std::endl; }
return 0; }