简体   繁体   English

为什么我无法使用相对路径在CLion中打开文件?

[英]Why am I not able to use relative path to open a file in CLion?

I seem to get errors when trying to open an std::ifstream if I use a relative path. 如果我使用相对路径,在尝试打开std::ifstream时似乎会出错。 Though it works fine if using an absolute path. 虽然使用绝对路径它可以正常工作。

Is there something I need to add to the CMakeLists.txt? 我需要添加到CMakeLists.txt吗? (I'm pretty new to using cmake) Or is it just a problem in CLion? (我对使用cmake很新)或者它只是CLion中的一个问题?

It's CLion. 这是克里昂。 You have to set the Working Directory in your compilation options. 您必须在编译选项中设置工作目录。 (under run > edit configurations) (正在运行>编辑配置)
For example: 例如: 设置截图

Because CLion works in an other directory on ubuntu under ~/.clion10/system/cmake/generated/[id_of_project] 因为CLion在ubuntu上的其他目录下工作~/.clion10/system/cmake/generated/[id_of_project]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM