C++获取当前目录

本文阅读 1 分钟
首页 应用开发 正文

1.说明

  • 如果只在windows平台使用,可使用_getcwd
  • 如果只在linux平台使用,可使用getcwd
  • 如果代码要跨平台使用,可以使用通过编译统一的版本
  • 函数释义:Get Current Working Directory

2.代码

#if defined(_MSC_VER)
    #include <direct.h>
    #define GetCurrentDir _getcwd
#elif defined(__unix__)
    #include <unistd.h>
    #define GetCurrentDir getcwd
#else
#endif

std::string get_current_directory() 
{
    char buff[250]; 
    GetCurrentDir(buff, 250);
    string current_working_directory(buff);
    return current_working_directory;
}
本文来自投稿,不代表本站立场,如若转载,请注明出处:
QByteArray的toHex()函数实现
« 上一篇 12-28
传奇单机架设
下一篇 » 01-24