I want to set the current directory to the solution diretory/configuration name. How do I do that? Can I use the global variables somehow?
Edit: I am trying to read a
If your current directory is changing, you should probably save your working directory at startup in some variable you can access later to set cwd back there. At least this is how I understand your question.
For getting the cwd, this might help.
You can use the posix subsystem ( <direct.h>
) and access the functions
_getcwd()/_wgetcwd() Gets the current working directory
_chdir()/_wchdir() Sets the current working directory
If you need your code to be cross platform, you can do the following:
#ifdef _WIN32
# include <direct.h>
# define getcwd _getcwd
# define chdir _chrdir
#else
# include <unistd.h>
#endif
and use getcwd
and chdir
(w/o the leading underscore).
For Visual Studio purposes (include header, etc) you can use macro like $(ProjectDir) or $(SolutionDir) listed here: VS macro list
To read files in code of your app use Windows API function GetCurrentDirectory that retrieves path to your process directory. Compiled code may live independently of project therefore it make sense to refer path to data files relatively to process (exe).
It seems author of question asks about 2-nd item and others answer to 1-st item.
Have you tried using the environment variable $(SolutionDir) ?
With reference to this thread here.
Also, hopefully the version of VS does not matter, but this answer is furnished based on the assumption that the platform is VS2005.
Hope this helps.
In Visual Studio 2010:
$(SolutionDir)$(Configuration)\
.Full list of available macros (on docs.microsoft.com) : Common macros for MSBuild commands and properties