c++ - How to find the keys of map which are not in the keys of another map? -



c++ - How to find the keys of map which are not in the keys of another map? -

i have declared 2 maps m1 , m2.

map m1's keys in keys of m2. keys of m2 not in keys of m1.

can help me how find uncommon keys in m2 compared keys of m1?

example

m1 contains:

3=> 1 2 4 6=> 3 4 6

m2 contains:

3 => 3 5 6 6 => 6 4 8 8 => 2 4 3 10 => 2 5 7 9

the output 8 , 10.

you can std::set_difference. example:

std::map<int, std::string> m1; m1[3] = "1 2 4"; m1[6] = "3 4 6"; std::map<int, std::string> m2; m2[3] = "3 5 6"; m2[6] = "6 4 8"; m2[8] = "2 4 3"; m2[10] = "2 5 7 9"; std::map<int, std::string> m3; std::set_difference(m2.begin(), m2.end(), m1.begin(), m1.end(), std::inserter(m3, m3.begin()), m1.value_comp()); (auto = m3.begin(); != m3.end(); ++i) { std::cout << "[" << i->first << "," << i->second << "]"; } std::cout << std::endl;

result:

[8,2 4 3][10,2 5 7 9]

live

c++ map

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -