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

后端 未结 23 1684
温柔的废话
温柔的废话 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:00

    If you want a standard way without libraries: No. The whole concept of a directory is not included in the standard.

    If you agree that some (portable) dependency on a near-standard lib is okay: Use Boost's filesystem library and ask for the initial_path().

    IMHO that's as close as you can get, with good karma (Boost is a well-established high quality set of libraries)

提交回复
热议问题