将Python词典转换为CPP对象
Converting a python dictionary to cpp object
我必须将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::map
或std::unordered_map
包含元素作为对。空间无法分开初始化器参数。正确的语法需要一组牙套,另一个用于向量。
相关文章:
- 我有两个类需要在同一 cpp 文件中相互引用,但第一个类无法识别第二个类类型的对象
- 在 cpp 中的平面缓冲区中序列化对象
- 链接列表在 cpp 中包含不同的对象类
- 如何从 cpp 中的函数返回自定义类对象?
- 为什么 const YAML::Node 对象的行为不像 yaml-cpp 中的类似值的对象?
- 我们可以在cpp中为对象分配函数吗
- 即使我正在.cpp文件中实例化一个伪对象,.cpp文件内模板函数的定义也不起作用
- afxmem.cpp中的对象初始化差异
- 从单个.cpp构建共享对象
- C++文件中.cpp静态对象声明
- 共享对象中的符号名称与文件中.cpp函数不同
- cpp 静态对象实例化
- 具有不同构造函数参数的 CPP 对象数组
- 将Python词典转换为CPP对象
- C 模板功能,相同类型,多个实例:共享一个相同的代码副本?即使在不同的CPP/对象文件中
- 在v8中,使用cpp对象作为参数执行js函数
- 在 cuda 内核中声明 CPP 对象
- cpp 对象方法是否有自己的堆栈帧
- 无法在 cpp 对象和头文件中使用 istream
- ZMQ:通过ZMQ队列发送自定义CPP对象