#include "stdafx.h" #include <string> #include <Windows.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 _tmain(int argc, _TCHAR* argv[]) { string str = "";
str = GetProgramDir(); cout << str << endl;
system("pause");
return 0; }