Get path of executable

前端 未结 23 1519
清歌不尽
清歌不尽 2020-11-22 07:04

I know this question has been asked before but I still haven\'t seen a satisfactory answer, or a definitive \"no, this cannot be done\", so I\'ll ask again!

All I wa

23条回答
  •  有刺的猬
    2020-11-22 07:33

    This method works for both Windows and Linux:

    #include 
    #include 
    #ifdef _WIN32
    #include 
    #define GetCurrentDir _getcwd
    #elif __linux__
    #include 
    #define GetCurrentDir getcwd
    #endif
    
    std::string GetCurrentWorkingDir() 
    {
        char buff[FILENAME_MAX];
        GetCurrentDir(buff, FILENAME_MAX);
        std::string current_working_dir(buff);
        return current_working_dir;
    }
    

提交回复
热议问题