How do I convert PWSTR to string in C++?

前端 未结 5 856
南笙
南笙 2020-12-11 04:41

I have the following code:

// Fetch Local App Data folder path.
PWSTR localAppData = (PWSTR) malloc(128);
SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-11 05:22

    I like Praetorina'sPraetorian's answer of just using wide string stream but if you want to convert:

    char str[128];
    wcstombs(str, localAppData, 128);
    

    There is another function which goes the other way around too:

    wchar_t wstr[128];
    mbstowcs(wstr, "Hello World", 128);
    

提交回复
热议问题