如何解码列表列表?
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
}
}
我有以下 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
}
}