我如何解码一个列表的列表
How can I decode a list of lists?
我有以下YAML文件,我需要在YAML - cpp中解码
WorldMatrix:
- [0.9951964247911349, 0.018388246064889716, -0.09615585520185603, -0.5403611888912607]
- [0.0668777651703494, 0.5895969306048771, 0.8049241106757379, 0.49102218903854067]
- [0.0714943396973693, -0.8074882858766219, 0.5855349926035782, 3.057906332726323]
- [0.0, 0.0, 0.0, 1.0]
我已经走了这么远,但我不知道如何继续:
YAML::Node config = YAML::LoadFile(path);
for(YAML::const_iterator it=config.begin(); it != config.end(); ++it){
}
如果您想使用std::vector
存储它,有一个快捷方式:
YAML::Node config = YAML::LoadFile(path);
std::vector<std::vector<double>> worldMatrix =
config["WorldMatrix"].as<std::vector<std::vector<double>>>();
如果你只是想迭代它,做任何你喜欢的事情:
for (YAML::Node row : config["WorldMatrix"]) {
for (YAML::Node col : row) {
double value = col.as<double>();
// do something with value
}
}
相关文章:
- 从链接列表c++中删除一个项目
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- 如何在C++中使用pybind11加载一个pickle python列表
- 链表,将列表复制到另一个列表
- 为什么它只打印双链接列表的第一个值,而我的程序却崩溃了
- 创建一个棋盘格或"Interweave"两个链接列表。IE 更改两个链表的指针
- 为什么在排序链表上的这种合并实现总是将两个列表都设置为 NULL,而只有一个应该设置一个列表?
- 测试迭代器是否位于列表中的最后一个
- 我如何创建一个列表,然后从中创建两个列表,其中一个用于偶数,另一个用于奇数?
- 动态分配列表 - 创建一个函数,用于删除所有包含偶数值的元素
- 给定一个源文件,有没有办法要求 gcc 返回仅直接包含的头文件的列表?
- 如何将列表从一个类复制到另一个类
- 删除链接列表中剩余的最后一个节点
- 处理程序的模块列表中有一个错误的模块"WebSocketModule"
- 避免在使用链接列表从 deque 中删除最后一个节点时出现内存泄漏
- 在 c++ 中创建一个类似 python 的列表
- 将两个列表合并为一个蛇形列表
- 如何将一个单词拆分成字母,并将它们放入一个无序的列表/集合中
- 遍历列表包含排除最后一个元素的内容
- 是否可以使用OpenMP并行化一个列表,该列表可以在每次迭代中添加新元素