我必须将 python 对象转换为 c++,但我对 python 一无所知。该对象看起来像这样:
VDIG = {
1024 : [1,2,3,4],
2048 : [5,6,7,8]
}
从外观上看,我认为它可能是列表 map ?
c++中可以使用的closes对象是什么?
我试过这样做,但它没有编译:
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::map
或 std::unordered_map
包含成对的元素。空格不能分隔初始化参数。正确的语法需要一组大括号表示对,另一个大括号表示 vector 。
关于python - 将 python 字典转换为 c++ 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54909080/