簡體   English   中英

無法將參數從 wchar_t[260] 轉換為 LPSTR

[英]Cannot convert argument from wchar_t[260] to LPSTR

我試圖在我的 windows 機器上獲取我的可執行文件的路徑。

    std::string get_exe_path_dir()
    {
        wchar_t path[MAX_PATH];
        GetModuleFileName( NULL, path, MAX_PATH );
        PathRemoveFileSpec(path);
            
        std::wstring ws(path);
        std::string str(ws.begin(), ws.end());
        return str.substr(0, str.find_last_of('/'));
    }

但現在我收到以下錯誤消息:

無法將參數 2 從“wchar_t [260]”轉換為“LPSTR”

我嘗試鑄造,但沒有奏效。

您正在使用顯式wchar_t而不是TCHAR ,因此您應該使用顯式 Unicode 版本GetModuleFileNameWPathRemoveFileSpecW而不是GetModuleFileNamePathRemoveFileSpec

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM