#include <windows.h>
#include <string>
#include <string.h>
#include <iostream>
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 path = GetProgramDir();
cout << path << endl;
while (1);
return 0;
}
发表评论: