c++ - 在第 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>();
你知道那是从哪里来的吗?
解决方案
错误来自程序没有找到正确路径的事实。我在我的类中解析文件,然后在方法中检索常量变量,所以我认为 yaml 节点或 yaml 路径之间的链接在我的方法中被破坏了。将yaml文件解析为我的类的公共成员并直接检索常量变量解决了这个问题。
推荐阅读
- sql - 替换存储在数据库中的逗号分隔列表
- node.js - 如何处理 MongoDB 的断开连接错误
- python - 调用 exe 需要来自不同文件夹的文本输入文件
- c++ - 无法在 Windows 10/Visual C++ 2017 上使用 tensorflow C++ API tensorflow_cc.lib 链接 C++——未定义符号 r2.0
- android - 添加 firebase_messaging 依赖项时,Android 在安装 app.apk 时挂起
- javascript - 在 JS 中如何以本地格式显示日期?
- python-3.x - 如何
使用 BeautifulSoup 从多个标签中抓取数据? - java - 我应该如何在只有特定用户 ID 的回收站视图中查询帖子?
- c# - SemaphoreSlim 不会限制任务
- javascript - javascript中的replaceWith问题