Question:
How to convert std::string
to std::wstring
?
Let's say:
std::string s = "some string";
std::wstring ws = f(s);
How can f()
be implemented?
Answer:
There are many ways… here are a couple…
//1
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::string str = converter.to_bytes(L"Hello world");
std::wstring wstr = converter.from_bytes("Hello world");
//2
std::string str("Hello world!!!");
std::wstring wstr(str.begin(), str.end());