unordered map Question 3

Last Updated :
Discuss
Comments

Merge two unordered map:

C++
#include <bits/stdc++.h>
using namespace std;

int main()
{
    unordered_map<int, string> map1 = {{1, "a"}, {2, "b"}};
    unordered_map<int, string> map2 = {{4, "x"}, {3, "y"}};
    map1.merge(map2);
}


map1 contains {1:"a", 2:"b", 3:"y", 4:"x"}, map2 is empty

map1 contains {1:"a", 2:"b", 3:"y"}, map2 has {2:"x"}

map1 remains unchanged

Compilation error

Share your thoughts in the comments