STL - Container/Container - Map
Map - insert()
Programmer.
2016. 2. 1. 17:05
소스)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include<iostream> #include<string> #include<map> void print(std::map<int, std::string> Target_Map) { for (std::map<int, std::string>::iterator IterPos = Target_Map.begin(); IterPos != Target_Map.end(); ++IterPos) std::cout << "Key->" << IterPos->first << ", Value->" << IterPos->second << " "; std::cout << std::endl; } void print(std::pair<int, std::string> Target_Pair) { std::cout << Target_Pair.first << " " << Target_Pair.second << std::endl; } void main() { std::map<int, std::string> Map; Map[1] = "First"; Map[2] = "Second"; std::map<int, std::string> Map2; Map[3] = "Third"; Map[4] = "Fourth"; print(Map); Map.insert(Map2.begin(), Map2.end()); print(Map); Map.insert(std::pair<int,std::string>(9,"nineth")); print(Map); Map.insert(Map.begin(),std::pair<int, std::string>(5, "fifth")); print(Map); } | cs |
내용)
insert()함수는 파라메터에 따라 다른기능을 합니다.
- insert(x,y) (26번)
이터레이터 x가 가리키는 곳 부터 이터레이터 y가 가리키는 곳 사이에 있는 데이터들을 삽입합니다. - insert(x) (28번)
pair x를 삽입합니다. - insert(x,y) (30번)
이터레이터 x가 가리키는 위치에 pair y를 삽입합니다.
결과)