In Visual Studio 2010 C++, I am reading argv[0] to get the working directory.
In debug mode it is definitely showing the full path of the directory and the exe file name itself (as expected)
In release mode it ONLY has the program .exe name, rather than the full working path.
- why?
- How to get working directory?
MSVC will place the command used to launch the executable into
argv[0]– this has nothing to do with the current working directory.For example, if the command used to launch
foo.exeis:foo, and the executable i found by searching the path,argv[0]will befooc:\foos-dir\foo, (the path will is not searched)argv[0]will bec:\foos-dir\foofoo.exe, argv[0] will befoo.exeetc.
You should probably get the current working directory using the Win32
GetCurrentDirectory()API or the_getcwd()runtime function.Here’s a short example using
GetCurrentDirectory():