Mike Wahler <mk******@mkwahler.net> wrote:
"Jay" <Co******@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com... Hello,
I am writing a c++ program that stores some values in a config located
in it's directory.
is there a way in c++ to get the full path of the running program so I
can open the file not relative to where I run it from but where it is
located?
Some implementations, e.g. for Windows, provide the full
path of the executable as main()'s argv[0]. But this is
not guaranteed by the language.
True that it is not guaranteed by the language. However, I think your
wording may be a little misleading: when I first read it, I interpreted
your statement as meaning that all implementations on Windows will
provide the full executable path. For example,
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "I am: " << argv[0] << '\n';
return 0;
}
only prints whatever I used to invoke the program. If I am in the same
directory as the program, I get:
I am: test
and if I move one directory down in the hierarchy but invoke the program
in the parent directory, I get:
I am: ..\test
--
Marcus Kwok