用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;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-09-08
  • 2021-06-22
猜你喜欢
  • 2021-12-25
  • 2022-12-23
  • 2021-07-09
  • 2021-11-14
  • 2022-12-23
相关资源
相似解决方案