I want to convert std::string into a const wchar_t *

后端 未结 4 1833
深忆病人
深忆病人 2020-11-28 08:44

Is there any method? My computer is AMD64.

::std::string str;
BOOL loadU(const wchar_t* lpszPathName, int flag = 0);

When I used:

4条回答
  •  萌比男神i
    2020-11-28 09:03

    You can use the ATL text conversion macros to convert a narrow (char) string to a wide (wchar_t) one. For example, to convert a std::string:

    #include 
    ...
    std::string str = "Hello, world!";
    CA2W pszWide(str.c_str());
    loadU(pszWide);
    

    You can also specify a code page, so if your std::string contains UTF-8 chars you can use:

    CA2W pszWide(str.c_str(), CP_UTF8);
    

    Very useful but Windows only.

提交回复
热议问题