Relative path to open file while running .app OSX C ++
I have a problem that I cannot solve alone. I have a file that I have to open in my program. It works when I use the absolute path from the root directory. When I use the relative path from the current folder it doesn't work.
I am using OSX. C ++.
Does not work:
filename = "../filefolder/lab.txt";
Works:
filename = "/Users/Thomas/Documents/Lab/filefolder/lab.txt"
.app is included in the directory src
that is in the directory Lab
, so the directory Lab
has two folders - src
and filefolder
. (Of course, I use ifstream myfile
and myfile.open(filename.c_str())
when string filename
).
Thanks for helping the guys!
EDIT: Now I figured out that doesn't even work when the file is in the main directory of the file: filename = "lab.txt"
or filename = "./lab.txt"
where lab.txt is included in the same directory as my .app program.
source to share
No one has answered this question yet
Check out similar questions: