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

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

    For Windows system at console you can use system(dir) command. And console gives you information about directory and etc. Read about the dir command at cmd. But for Unix-like systems, I don't know... If this command is run, read bash command. ls does not display directory...

    Example:

    int main()
    {
        system("dir");
        system("pause"); //this wait for Enter-key-press;
        return 0;
    }
    

提交回复
热议问题