How can I concatenate the following two maps?
map<string, map<string,string>> map1;
map<string, map<string,string>> map2;
I just want to add map2 to map1 and keep all elements already in map1, i.e., add map2 at the end of map1. I’ve tried map1.insert(map2.begin(), map2.end()), but it does not work since it overwrites old elements in map1.
The question contradicts with the concept of a map. If you insert a value in a map, you expect it to be at ‘the proper place’, depending on it’s key. This implies there is only one entry for each key.
Instead, you could use a
vector< pair< mymap::key, myamap::value > >and fill it with the entries of the first resp. the second map.