#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;
}
结果: