How can I merge two STL maps into one? They both have the same key and value types (map<string, string>). If there is an overlap of the keys, I would like to give preference to one of the maps.
How can I merge two STL maps into one? They both have the same
Share
Assuming you want to preserve the elements in
mapA, and merge elements inmapBfor which there is no key inmapA:will do what you want, I think.
(EDIT: If you are using C++17 or newer, consider this answer: https://stackoverflow.com/a/56594603/118150)
Working example:
output: