当使用 std::array 时,我可以一次赋值:
std::array<int, 3> a2 = {1, 2, 3};
但是当上面的数组组合成一个映射时,我不知道最好的方法:
using namespace std;
map <string, array<int, 3>> myMap;
//I'm doing it like below now...
array<int, 3> tempArray = {1,2,3}; // can I save this line somehow?
myMap[myString] = tempArray;
如果这实际上是正确的方法,请告诉我。谢谢!
最佳答案
虽然使用另一个答案中所示的 insert
效率更高,但您也可以使用
myMap["foo"] = {{1,2,3}};
如果简洁的代码对你来说更重要。
关于c++ - 为 std::map 中的 std::array 分配多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15734611/