How do I get the directory that a program is running from?

后端 未结 23 1683
温柔的废话
温柔的废话 2020-11-22 04:39

Is there a platform-agnostic and filesystem-agnostic method to obtain the full path of the directory from where a program is running using C/C++? Not to be confused with the

23条回答
  •  后悔当初
    2020-11-22 05:02

    On POSIX platforms, you can use getcwd().

    On Windows, you may use _getcwd(), as use of getcwd() has been deprecated.

    For standard libraries, if Boost were standard enough for you, I would have suggested Boost::filesystem, but they seem to have removed path normalization from the proposal. You may have to wait until TR2 becomes readily available for a fully standard solution.

提交回复
热议问题