调用了Win API
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
wstring GetRunDir()
{
wstring Path;
wchar_t szModule[1024] = { 0 };
GetModuleFileName(NULL, szModule, sizeof(szModule) / sizeof(szModule[0]));
Path = szModule;
Path.erase(Path.find_last_of(L'\\'));
return Path;
}
int main()
{
std::wcout << GetRunDir();
}

该代码示例演示了如何使用Windows API函数GetModuleFileName来获取当前运行程序的完整路径,并通过删除最后一个反斜杠得到运行目录。这是一个基础的系统编程技巧,常用于需要定位到程序执行文件所在目录的场景。
6万+

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



