GetModuleFileName 获得运行文件路径的问题
#include "Shlwapi.h"#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;
string GetProgramDir()
{
TCHAR 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;
}
运行后显示 error C2440: 'type cast' : cannot convert from 'TCHAR [260]' to 'std::string'。不知如何更改,请各路高手支招,多谢!