Converting TCHAR to string in C++

后端 未结 5 983
-上瘾入骨i
-上瘾入骨i 2020-12-20 11:24

I\'m trying to convert a TCHAR to a string as in:

std::string mypath;
TCHAR path[MAX_PATH];
GetModuleFileName( NULL, path, MAX_PATH );

I ne

5条回答
  •  醉话见心
    2020-12-20 11:42

    When I really need to do it I use the following:

    TCHAR  infoBuf[32767];
    GetWindowsDirectory(infoBuf, 32767);
    

    And then I convert it to a wstring which can be converted to a standard std::string:

    wstring test(&infoBuf[0]); //convert to wstring
    string test2(test.begin(), test.end()); //and convert to string.
    

提交回复
热议问题