gpt4 book ai didi

c++ - C++ 中的 4d 映射与元组

转载 作者:行者123 更新时间:2023-11-30 03:13:50 25 4
gpt4 key购买 nike

这个有点类似这个问题4d mapping in C++?以及我之前关于 C++ map 的问题之一 Use a map with the map name defined by a string C++

我有一个看起来像这样的代码(它不起作用并停在向 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";
}

我想做的是给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 map 与元组相结合?

最佳答案

更改您的分配,使其实际上可以形成一个 tuple<string, string> (注意右边的引号):

mapMapMap[myCarmapMapMap]["3 series"][Number] = {"90", "20"};

Example

此外,删除 ,在行尾。

您的查询可能可以通过包含 Number 来修复再次,喜欢:

string output = get<0>(mapMapMap[myCarmapMapMap].find("3 series")->second[Number]);

关于c++ - C++ 中的 4d 映射与元组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58378750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com