C++ Convert string (or char*) to wstring (or wchar_t*)

后端 未结 16 2187
难免孤独
难免孤独 2020-11-22 05:57
string s = \"おはよう\";
wstring ws = FUNCTION(s, ws);

How would i assign the contents of s to ws?

Searched google and used some techniques but

16条回答
  •  既然无缘
    2020-11-22 06:50

    From char* to wstring:

    char* str = "hello worlffffd";
    wstring wstr (str, str+strlen(str));
    

    From string to wstring:

    string str = "hello worlffffd";
    wstring wstr (str.begin(), str.end());
    

    Note this only works well if the string being converted contains only ASCII characters.

提交回复
热议问题