how to change the working directory to the location of the program

后端 未结 4 1633
情书的邮戳
情书的邮戳 2020-12-10 19:55

I want to use c++ to open a file on Mac OS.

If I run the program under Xcode, the working directory is the same with the program, which is fine. However, if I try t

4条回答
  •  隐瞒了意图╮
    2020-12-10 20:28

    You could use chdir(), see here: Change the current working directory in C++.

    Or if you could always just issue a system call (stdlib.h): http://www.cplusplus.com/reference/clibrary/cstdlib/system/. This won't be portable, but it might be good enough for what you need.

提交回复
热议问题