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;
}
本文来自投稿,不代表本站立场,如若转载,请注明出处: