编码过程中有时候会用到获取工程所在路径或者exe所在的路径信息,这里稍微记录下。
获取工程路径
char pBuf[MAX_PATH]; //存放路径的变量
GetCurrentDirectory(MAX_PATH,pBuf); //获取程序的当前目录
获取可执行程序所在路径
std::string GetProgramDir()
{
char exeFullPath[MAX_PATH]; // Full path
std::string strPath = ""; GetModuleFileName(NULL,exeFullPath,MAX_PATH); //获取带有可执行文件名路径
strPath=(std::string)exeFullPath;
int pos = strPath.find_last_of('\\', strPath.length());
return strPath.substr(, pos); // 返回不带有可执行文件名的路径
}
参考
https://www.cnblogs.com/pegasus923/archive/2010/11/02/1867584.html