1. 程式人生 > 其它 >C++ 獲取當前執行程式的路徑

C++ 獲取當前執行程式的路徑

技術標籤:C++

GetModuleFileName獲取當前程序已載入模組的檔案的完整路徑,該模組必須由當前程序載入。
其標頭檔案為windows.h

#include <windows.>

std::string GetAppPath()
{
	char buffer[512] = {0};
	GetModuleFileName(nullptr, buffer, sizeof(512));
	std::string appPath = buffer;
	appPath = appPath.substr(0, appPath, rfind("\\"));
return appPath; }

注意,其返回的路徑值使用的分隔符為\\,例如D:\\Test\\Result\\Test.exe。