【发布时间】:2019-10-14 14:20:24
【问题描述】:
这有点类似于这个问题4d mapping in C++? 和我之前关于 C++ 地图的问题之一Use a map with the map name defined by a string C++
我有一个看起来像这样的代码(它不起作用并停在为地图提供输入的行):
#include <iostream>
#include <string>
#include <tuple>
#include <map>
#include <vector>
using namespace std;
int main()
{
map<string, //Volkswagen (car brand)
map<string, //series
map<int, //in this example 1
tuple<string, string>>>> mapMapMap;
string myCarmapMapMap = "Volkswagen";
int Number = 1;
mapMapMap[myCarmapMapMap]["3 series"][Number] = {90, 20};,
string Output;
Output.assign(get<0>(mapMapMap[myCarmapMapMap].find("3 series")->second));
cout << "\n" << "------------" << "\n" << Output << "\n"<< "------------" << "\n";
}
我想做的是为Volkswagen、3 series、1 分配两个值,然后可以这样调用它:
Volkswagen -> 3 series -> 1 -> <0> (value 1).
这是我收到的错误消息:
|19|error: expected primary-expression before ',' token|
我也试过了:
mapMapMap.insert({myCarmapMapMap, "3 series", Number, {"90", "20"}});
但它也不起作用。如何将 4d 地图与元组结合起来?
【问题讨论】:
-
您期望
tuple<string, string>,但您尝试分配整数90和20。 -
您收到的错误消息应该包含足够的信息来解决问题。
-
没错,但把“”放在周围没有帮助。
-
那么你需要告诉我们你所说的“它不起作用”是什么意思。你有构建错误吗?请将完整且完整的错误输出复制粘贴到问题中。并请刷新how to ask good questions,以及this question checklist。
-
谢谢,我更新了错误信息。
标签: c++ dictionary