전역변수 std::map<int, int> 초기화하는 방법
조회수 9355회
1 답변
-
1. C++11에서
#include <map> using namespace std; map<int, char> m = {{1, 'a'}, {3, 'b'}, {5, 'c'}, {7, 'd'}};
2. 함수를 정의해서
map<int,int> create_map() { map<int,int> m; m[1] = 2; m[3] = 4; m[5] = 6; return m; } map<int, int> mymap = create_map();
3. Boost.Assign 사용
#include <map> #include "boost/assign.hpp" using namespace std; using namespace boost::assign; map<int, char> m = map_list_of (1, 'a') (3, 'b') (5, 'c') (7, 'd');
댓글 입력