如何创建C++映射-没有构造函数的实例


std::map<string, bool> action_map = { 
{'0_0', true}, {'0_1', false}, {'0_2', false}, {'0_3', false}, {'0_4', true},
{'1_0', true}, {'1_1', false}, {'1_2', false}, {'1_3', true},
{'2_0', true}, {'2_1', false}, {'2_2', false}, {'2_3', true},
{'3_0', true}, {'3_1', false}, {'3_2', false}, {'3_3', true}
};

错误:

error: no matching constructor for initialization of 'std::map<string, bool>' (aka 'map<basic_string<char>, bool>')
std::map<string, bool> action_map = { 
^            ~
/bits/stl_map.h:290:2: note: candidate constructor template not viable: requires at most 4 arguments, but 17 were provided
map(_InputIterator __first, _InputIterator __last,
^
/bits/stl_map.h:228:7: note: candidate constructor not viable: requires at most 3 arguments, but 17 were provided
map(initializer_list<value_type> __l,
^
/bits/stl_map.h:256:2: note: candidate constructor template not viable: requires 3 arguments, but 17 were provided
map(_InputIterator __first, _InputIterator __last,
^
/bits/stl_map.h:194:7: note: candidate constructor not viable: requires at most 2 arguments, but 17 were provided
map(const _Compare& __comp,
^
/bits/stl_map.h:240:7: note: candidate constructor not viable: requires 2 arguments, but 17 were provided
map(const map& __m, const allocator_type& __a)
^
/bits/stl_map.h:244:7: note: candidate constructor not viable: requires 2 arguments, but 17 were provided
map(map&& __m, const allocator_type& __a)
^
/bits/stl_map.h:250:7: note: candidate constructor not viable: requires 2 arguments, but 17 were provided
map(initializer_list<value_type> __l, const allocator_type& __a)
^
/bits/stl_map.h:273:2: note: candidate constructor template not viable: requires 2 arguments, but 17 were provided
map(_InputIterator __first, _InputIterator __last)
^
/bits/stl_map.h:207:7: note: candidate constructor not viable: requires 1 argument, but 17 were provided
map(const map&) = default;
^
/bits/stl_map.h:215:7: note: candidate constructor not viable: requires 1 argument, but 17 were provided
map(map&&) = default;
^
/bits/stl_map.h:236:7: note: candidate constructor not viable: requires single argument '__a', but 17 arguments were provided
map(const allocator_type& __a)
^
/bits/stl_map.h:185:7: note: candidate constructor not viable: requires 0 arguments, but 17 were provided
map() = default;

在C++中,单引号''用于表示字符(字符常量(。

要表示字符串,应该使用双引号""

std::map<string, bool> action_map = { 
{"0_0", true}, {"0_1", false}, {"0_2", false}, {"0_3", false}, {"0_4", true},
{"1_0", true}, {"1_1", false}, {"1_2", false}, {"1_3", true},
{"2_0", true}, {"2_1", false}, {"2_2", false}, {"2_3", true},
{"3_0", true}, {"3_1", false}, {"3_2", false}, {"3_3", true}
};