获取C++项目运行绝对路径:
// filePath 就是项目所在绝对路径
char* projectPath = nullptr;
projectPath = _getcwd(nullptr, 1);
string filePath(projectPath);
...
// 用完删除
delete projectPath;
projectPath = nullptr;
该篇博客介绍了如何在C++程序中获取项目运行的当前工作目录。通过使用_cwd函数,可以得到项目的绝对路径,并将其转换为字符串类型便于后续处理。在使用完毕后,别忘了释放内存。
获取C++项目运行绝对路径:
// filePath 就是项目所在绝对路径
char* projectPath = nullptr;
projectPath = _getcwd(nullptr, 1);
string filePath(projectPath);
...
// 用完删除
delete projectPath;
projectPath = nullptr;
2273
2280

被折叠的 条评论
为什么被折叠?