将python字典转换为cpp对象

DEK*_*KER 4 c++ python dictionary

我必须将python对象转换为c ++,但我不知道python.该对象如下所示:

VDIG = {
    1024 : [1,2,3,4],
    2048 : [5,6,7,8]
}
Run Code Online (Sandbox Code Playgroud)

从它的外观我认为它可能是一个列表的地图?

什么是可以在c ++中使用的关闭对象?

我尝试这样做,但它不编译:

std::map<int, std::list<int>> G_Calib_VoltageDigits = {
    1024 {1,2,3},
    2048 {4, 5, 6}
};
Run Code Online (Sandbox Code Playgroud)

所以我的问题是Python中的数据类型是什么,以及在c ++中使用类似内容的最佳方法是什么?

Gui*_*cot 7

你几乎得到了正确的语法:

#include <unordered_map>
#include <vector>

std::unordered_map<int, std::vector<int>> G_Calib_VoltageDigits = {
    {1024, {1, 2, 3}},
    {2048, {4, 5, 6}}
};
Run Code Online (Sandbox Code Playgroud)

实例

说明:a std::map或a std::unordered_map包含作为pair的元素.空格不能分隔初始化参数.正确的语法需要一对大括号,另一个用于向量.