标题:GetModuleFileName 获得运行文件路径的问题
取消只看楼主
smart3503
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-1-19
结帖率:100%
已结贴  问题点数:20 回复次数:1 
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'。不知如何更改,请各路高手支招,多谢!
搜索更多相关主题的帖子: return without include namespace pos 
2013-01-29 13:37
smart3503
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-1-19
得分:0 
多谢版主指教,可以了,学的不精,以后多来向版主学习
2013-01-29 14:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-397849-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.839601 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved