c++基础之获取当前可执行程序相关的信息

#include 
#include 
namespace fs = std::filesystem;
using namespace std;

std::string getAppPath()
{
	char szPath[256] = { 0 };
	int nSize = GetModuleFileNameA(NULL, szPath, sizeof(szPath));
	if (nSize <= 0)
	{
		return "";
	}
	return szPath;
}

int main()
{
	
	string strPath = getAppPath();
	cout << strPath.c_str() << endl;

	fs::path pa(strPath);
	cout << pa.filename() << endl;//test.exe

	cout << pa.stem().string() << endl;//文件名test
	cout << pa.extension().string() << endl;//扩展名exe



	system("pause");
	return 0;
}

结果:
c++基础之获取当前可执行程序相关的信息_第1张图片

你可能感兴趣的:(C/C++基础,c++,开发语言)