与fstream c ++的相对路径 [英] Relative path with fstream c++

查看:239
本文介绍了与fstream c ++的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试加载一个文件与fstream。代码如下所示

  file.open(../ levels / level0.lvl); 
if(file.is_open()){
while(!file.eof()){
std :: getline(file,Str);
list = ReadLine(Str,list);
}
}

仅当路径是绝对路径时才有效。
如何使路径相对?



文件夹levels位于debug文件夹中。

文件夹级别托管在文件夹文件夹中。

<$ c

$ c> levels 文件夹与可执行文件的路径有关。

确定相对路径的相关文件夹是可执行文件实际起始的工作目录。






请参阅: fstream也不解析路径


I try to load a file with fstream. The code looks like this

file.open("../levels/level0.lvl");
if (file.is_open()) {
    while (!file.eof()) {
        std::getline(file, Str);
        list = ReadLine(Str, list);
    }
}

But it loads nothing. Yes only if the path is absolute. How can I make the path relative?

The folder "levels" is hosted in the debug folder. same folder as the exe.

解决方案

"The folder "levels" is hosted in the debug folder. same folder as the exe."

It doesn't matter in which position the levels folder is in relation to the executable's path.
The relevant folder to determine the relative path is the working directory where your executable is actually started from.


See here: fstream doesn't resolve path also.

这篇关于与fstream c ++的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆