C ++中具有元组的4D映射 [英] 4d mapping in C++ with tuple
问题描述
这有点类似于这个问题 C ++中的4d映射?,也是我以前的问题之一C ++中关于地图的问题使用地图地图名称由字符串C ++定义
This is somewhat similar to this problem 4d mapping in C++? and one of my previous questions on maps in C++ Use a map with the map name defined by a string C++
我有一个看起来像这样的代码(该代码不起作用,停在向地图提供输入的行上):
I have a code that looks like this (that does not work and stops at the line giving input to the map):
#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";
}
我想要做的是为大众汽车,三系3系列,一1代号分配两个值,然后可以像这样调用它: Volkswagen->3系列->1->< 0>(值1).
What I want to do is to assign two values to Volkswagen
, 3 series
, 1
and then be able to call it like:
Volkswagen -> 3 series -> 1 -> <0> (value 1).
这是我收到的错误消息: | 19 |错误:,"令牌之前的预期主表达式|
This is the error message I get:
|19|error: expected primary-expression before ',' token|
我也尝试过:
mapMapMap.insert({myCarmapMapMap,"3 series",Number,{"90","20"}});
但是它也不起作用.如何将4d地图与元组结合在一起?
But it does not work either. How do I combine a 4d map with a tuple?
推荐答案
更改分配,以便实际上可以形成 tuple< string,string>
(请注意右侧的引号):
Change your assignment so it can actually form a tuple<string, string>
(note the quotation signs on the right hand side):
mapMapMap[myCarmapMapMap]["3 series"][Number] = {"90", "20"};
此外,删除行末的
.
您的查询很可能可以通过再次包含 Number
来解决,例如:
Your query can, probably, be fixed by including the Number
again, like:
string output = get<0>(mapMapMap[myCarmapMapMap].find("3 series")->second[Number]);
这篇关于C ++中具有元组的4D映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!