How to convert wstring into string?

前端 未结 17 2167
北海茫月
北海茫月 2020-11-22 13:10

The question is how to convert wstring to string?

I have next example :

#include 
#include 

int main()
{
    std::wstr         


        
17条回答
  •  独厮守ぢ
    2020-11-22 13:20

    I am using below to convert wstring to string.

    std::string strTo;
    char *szTo = new char[someParam.length() + 1];
    szTo[someParam.size()] = '\0';
    WideCharToMultiByte(CP_ACP, 0, someParam.c_str(), -1, szTo, (int)someParam.length(), NULL, NULL);
    strTo = szTo;
    delete szTo;
    

提交回复
热议问题