visual studio – How do I set the working directory to the solution directory in c++?

visual studio – How do I set the working directory to the solution directory in c++?

In Visual Studio 2010:

  1. Go to the project properties (rigth click on the project name in the Solution Explorer, then Properties on the pop up menu).
  2. Then, under Configuration Properties / Debugging, set Working Directory to $(SolutionDir)$(Configuration).

Full list of available macros (on docs.microsoft.com) : Common macros for MSBuild commands and properties

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).

visual studio – How do I set the working directory to the solution directory in c++?

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.

Leave a Reply

Your email address will not be published.