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)。

おすすめ

転載: blog.csdn.net/xp178171640/article/details/113716358