python - 将 python 字典转换为 cpp 对象
问题描述
我必须将 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}}
};
解释: astd::map
或 astd::unordered_map
包含元素作为对。空格不能分隔初始值设定项参数。正确的语法需要一组大括号用于该对,另一个用于向量。
推荐阅读
- vba - 将变量从 vba 传递到 .bat 文件
- python - Python。Tor 浏览器。虚拟专用网。代理人
- python - 如何在 celery worker 中一次只执行一项任务,而不会丢失它并保持队列中任务的顺序
- sql - SQL 字符串转 int(日期)
- python - 为什么我的代码在添加此列表值后停止
- html - 如何使用输入文本框内联按钮/下拉菜单?
- node.js - Express:如何将请求响应发送到同一页面
- c++ - 关闭后Boost Beast重新连接websocket连接
- r - 从现有数据集创建时间序列
- javascript - 一旦用户在 magento 中单击关闭,就隐藏整个会话顶部的横幅