#include <iostream>
#include <string>
#include <windows.h>
int main(int argc,char **argv)
{
char szFilePath[MAX_PATH + 1] = { 0 };
GetModuleFileNameA(NULL, szFilePath, MAX_PATH);
(strrchr(szFilePath, '\\'))[0] = 0; // 删除文件名,只获得路径字串
std::string path = szFilePath;
std::cout << path << std::endl;
}
vs2017 C++获取exe路径
最新推荐文章于 2023-12-28 12:27:18 发布
本文介绍了一个简单的C++程序,该程序使用Windows API函数GetModuleFileNameA来获取当前正在运行的程序所在目录的完整路径,并通过修改最后一个字符为null终止符的方式去除路径中的文件名部分,最终仅保留目录路径。
808

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



