gpt4 book ai didi

c++ - 如何解码列表列表?

转载 作者:太空宇宙 更新时间:2023-11-04 13:26:47 26 4
gpt4 key购买 nike

我有以下 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++ - 如何解码列表列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33072996/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com