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

后端 未结 16 2414
难免孤独
难免孤独 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:49

    std::string -> wchar_t[] with safe mbstowcs_s function:

    auto ws = std::make_unique(s.size() + 1);
    mbstowcs_s(nullptr, ws.get(), s.size() + 1, s.c_str(), s.size());
    

    This is from my sample code

提交回复
热议问题