将Python词典转换为CPP对象

Converting a python dictionary to cpp object

本文关键字:CPP 对象 转换 Python      更新时间:2023-10-16

我必须将python对象转换为c ,但我对python不了解。对象看起来像这样:

VDIG = {
    1024 : [1,2,3,4],
    2048 : [5,6,7,8]
}

从外观上看,我认为它可能是列表的地图?

C 中可以使用的关闭对象是什么?

我试图这样做,但没有编译:

std::map<int, std::list<int>> G_Calib_VoltageDigits = {
    1024 {1,2,3},
    2048 {4, 5, 6}
};

所以我的问题是python中的数据类型是什么,什么是C 中类似内容的最佳方法?

您几乎正确地说了语法:

#include <unordered_map>
#include <vector>
std::unordered_map<int, std::vector<int>> G_Calib_VoltageDigits = {
    {1024, {1, 2, 3}},
    {2048, {4, 5, 6}}
};

实例示例

说明:std::mapstd::unordered_map包含元素作为对。空间无法分开初始化器参数。正确的语法需要一组牙套,另一个用于向量。