C++实现获取当前执行文件全路径

用GetModuleFileName(NULL,exeFullPath,MAX_PATH)得到当前执行文件的全路径。

 

#include <Windows.h>	
#include <iostream>	
#include <string>	
using namespace std;	
	
string GetProgramDir()	
{	
	char exeFullPath[MAX_PATH];	// Full path
	string strPath = "";

	GetModuleFileName(NULL,exeFullPath,MAX_PATH);
	strPath=(string)exeFullPath;	// Get full path of the file
	int pos = strPath.find_last_of('\\', strPath.length());
	return strPath.substr(0, pos);	// Return the directory without the file name
}	

int main ()
{
	string str = "";

	str = GetProgramDir();
	cout << str << endl;

	return 0;
}

 

原文链接: https://www.cnblogs.com/pegasus923/archive/2010/11/02/1867584.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    C++实现获取当前执行文件全路径

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/16893

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月7日 下午5:19
下一篇 2023年2月7日 下午5:19

相关推荐