class Restaurant { public: std::string name; std::set<std::string> food; }; class Owner { public: Restaurant *res; int position; }
std::vector<Owner> vec;
for (auto v : vec ){ cout << v.res->name << "- " << v.position << endl; }
branch1- 4 branch2- 10 branch3- 3 branch1- 2
branch1- 6 branch2- 10 branch3- 3
std::map<std::string, int> groups; //Build the map from the vector; for(auto v : vec) { groups[v.res->name] += v.position; } // print it out for(auto totals : groups) { std::cout << totals.first << "- " << totals.second << std::endl; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)