首页 > 解决方案 > 在第 0 行第 0 列出现错误:转换错误

问题描述

我不知道为什么会收到此错误:

terminate called after throwing an instance of 'YAML::TypedBadConversion<double>'
what():  yaml-cpp: error at line 0, column 0: bad conversion
Aborted (core dumped)

我将我的 constant.yaml 文件缩减为: MAX_FINGER_APERTURE: 0.120 我的代码如下:

//Path to the constants yaml file
std::string pkg_path = ros::package::getPath("frasier_motion");
std::string constants_path = pkg_path + "/config/constant.yaml";
YAML::Node constants = YAML::LoadFile(constants_path);

double MAX_FINGER_APERTURE = constants["MAX_FINGER_APERTURE"].as<double>();

你知道那是从哪里来的吗?

标签: c++yaml-cpp

解决方案


错误来自程序没有找到正确路径的事实。我在我的类中解析文件,然后在方法中检索常量变量,所以我认为 yaml 节点或 yaml 路径之间的链接在我的方法中被破坏了。将yaml文件解析为我的类的公共成员并直接检索常量变量解决了这个问题。


推荐阅读