Converting TCHAR to string in C++

后端 未结 5 976
-上瘾入骨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条回答
  •  Happy的楠姐
    2020-12-20 11:43

    TCHAR is a macro defined as a char or wchar depending on what you have your character set defined to. The default after 2008 is have the character set to unicode. this code works if you change your character set.

    int _tmain(int argc, _TCHAR* argv[])
    {
        TCHAR* bob ="hi";
        string s = bob;    
    }
    

    Right click on the project settings and chage the folowing

    enter image description here

    if You want to use TCHAR as a Unicode character set use wstring

提交回复
热议问题