版权声明:快乐源自分享,欢迎高手指正错误。 https://blog.csdn.net/gdnh22a/article/details/84025893
C++11获取方法
std::string GetCurrentExePath()
{
const int kBUF_SIZE = 10240;
std::unique_ptr<char[]> pBuf(new char[kBUF_SIZE]);
GetModuleFileNameA(nullptr, pBuf.get(), kBUF_SIZE); //完整路径含exe名称
std::string strTemp(pBuf.get());
int iIndex = strTemp.find_last_of('\\'); //找到最后一个反斜杠
return strTemp.substr(0, iIndex);//拷贝反斜杠前面的串
}