【发布时间】:2019-07-06 11:26:43
【问题描述】:
我正在尝试使用 yaml-cpp 解析 yaml 文件,但它需要 file.yaml 的完整路径。如果它可能因用户设置而异,我应该如何获得此路径。我假设这个文件名不会改变
这是针对 ROS 动力学框架的,所以它在 linux 上运行。我已经尝试使用 system() 函数获取此路径,但它没有返回字符串。
string yaml_directory = system("echo 'find -name \"file.yaml\"' ") ; // it's not working as expected
YAML::Node conf_file = YAML::LoadFile("/home/user/path/path/file.yaml"); //I want to change from that string to path found automatically
【问题讨论】:
-
你用 realpath 命令试过了吗?
-
realpath 打印路径,但它只能在 bash 中正常工作 - 在 cpp system() 中不要将此路径作为字符串返回