How do I convert wchar_t* to std::string?

前端 未结 6 1521
孤独总比滥情好
孤独总比滥情好 2020-12-09 08:16

I changed my class to use std::string (based on the answer I got here but a function I have returns wchar_t *. How do I convert it to std::string?

I tried this:

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 08:23

    Following code is more concise:

    wchar_t wstr[500];
    char string[500];
    sprintf(string,"%ls",wstr);
    

提交回复
热议问题