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

#include <iostream>
#include <filesystem>
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;
}

结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/FairLikeSnow/article/details/130912472