If I have an executable: project/bin/exec
, which caches data into a file.txt
in its active directory, the location where file.txt
will be saved depends on how I run the program:
project/file.txt
if I run it fromproject
withbin/exec
project/bin/file.txt
if I run it fromproject/bin
with./exec
I'd like the program to always use the directory of the executable and I'd like to find out if there's a non-programatic way of forcing it to do it.
I'm interested in UNIX/Windows, does this even make sense?
Programatically, I know I could get the executable's directory by using boost
or std::experimental
filesystem
, perhaps args[0]
argument and use that path for I/O.
Is that the way to do it?