#if WIN32
#include <windows.h>
std::string getAppDirPath() {
char buffer[MAX_PATH];
GetModuleFileName(NULL, buffer, MAX_PATH);
*strrchr(buffer, '\\') = 0;
return buffer;
}
#else
#include <unistd.h>
#include <string.h>
#include <iostream>
using namespace std;
string getAppDirPath()
{
char buffer[1024];
int cnt = readlink("/proc/self/exe", buffer, 1024);
if (cnt < 0 || cnt >= 1024)
{
return NULL;
}
*strrchr(buffer, '/') = 0;
return buffer;
}
#endif
C++ 获取程序运行路径
最新推荐文章于 2024-07-15 15:38:25 发布