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.

+3
c ++ macos


source to share


No one has answered this question yet

Check out similar questions:

1709
How can I profile C ++ code running on Linux?
7
How can I open a file with its relative path in Linux?
6
Android.mk relative or absolute paths?
2
UNIX: list files in directory with relative path
2
relative path in QtCreator
2
Relative paths in otool output?
0
Determining the relative include path
0
Qt 5.3 Relative path not found on Mac OSX
0
Passing relative path on OSX to C
0
Can't open file with relative path? (C ++ ifstream)



All Articles
Loading...
X
Show
Funny
Dev
Pics