我如何解码一个列表的列表

How can I decode a list of lists?

本文关键字:列表 一个 解码 何解码      更新时间:2023-10-16

我有以下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
  }
}