I have the following structure.
struct Tourist { string name; string surname; string sex; }; I would like to sort tourists by families.
int getMinRoomsAmount(Tourist touristsList[]) { map<string, Tourist[]> families; for (int i=0; i < 40; i++) { families[touristsList[i].surname] = // to append the array with the tourist } return 0; } Is it possible to have a map where the key is a string, and the value is an array of structures? And how can I append the array with new entries?
std::vectors can be. This is whatstd::vectoris for, so what you want isstd::map<std::string, std::vector<Tourist>>, however if your goal is to sort it by surname, you don't even need that. just put everything in a singlestd::vectorand usestd::sortwith a custom comparator lambda. Much simpler, and easier.a=bwould work, when bothaandbare arrays. Obviously, that's not the case.