관리 메뉴

Kim's Programming

Map - Operator [] 본문

STL - Container/Container - Map

Map - Operator []

Programmer. 2016. 2. 1. 17:43

소스)


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
#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";
    Map[3= "Third";
 
    print(Map);
    std::cout << Map[2<< std::endl;
    print(Map);
 
}
cs


내용)


연산자 [x]는 key값이 x인 pair의 second(value)를 리턴하거나 =연산자를 이용하여 value를 수정도 할 수 있습니다.


결과)




'STL - Container > Container - Map' 카테고리의 다른 글

Map - rend()  (0) 2016.02.01
Map - rbegin()  (0) 2016.02.01
Map - Operator '='  (0) 2016.02.01
Map - max_size()  (0) 2016.02.01
Map - lower_bound()  (0) 2016.02.01