How do I set the working directory to the “solution directory” in c++?

后端 未结 5 1195
生来不讨喜
生来不讨喜 2020-12-30 02:01

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

5条回答
  •  再見小時候
    2020-12-30 02:27

    1. For Visual Studio purposes (include header, etc) you can use macro like $(ProjectDir) or $(SolutionDir) listed here: VS macro list

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

提交回复
热议问题