[C++] merge
Updated:
개요
- 다른 컨테이너의 노드를 연결
예제
- 코드
#include <iostream> #include <map> #include <string> using namespace std; int main() { map<int, string> m1{{1, "a"}, {2, "b"}, {3, "c"}}; map<int, string> m2{{4, "d"}, {5, "e"}, {6, "f"}}; for (const auto &iter : m1) { cout << iter.first << ", " << iter.second << endl; } cout << "------ 1" << endl; for (const auto &iter : m2) { cout << iter.first << ", " << iter.second << endl; } cout << "------ 2" << endl; m1.merge(m2); for (const auto &iter : m1) { cout << iter.first << ", " << iter.second << endl; } cout << "------ 3" << endl; for (const auto &iter : m2) { cout << iter.first << ", " << iter.second << endl; } cout << "------ 4" << endl; return 0; }
- 실행 결과
1, a 2, b 3, c ------ 1 4, d 5, e 6, f ------ 2 1, a 2, b 3, c 4, d 5, e 6, f ------ 3 ------ 4