Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative path with fstream c++

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.

like image 970
SaschaDeWaal Avatar asked Jan 27 '15 21:01

SaschaDeWaal


Video Answer


1 Answers

"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.

like image 130
πάντα ῥεῖ Avatar answered Nov 15 '22 06:11

πάντα ῥεῖ