If I have a UTF-8 std::string how do I convert it to a UTF-16 std::wstring? Actually, I want to compare two Persian words.
std::string
std::wstring
This is how you do it with C++11:
std::string str = "your string in utf8"; std::wstring_convert<std::codecvt_utf8_utf16<char16_t>> converter; std::wstring wstr = converter.from_bytes(str);
And these are the headers you need:
#include <iostream> #include <string> #include <locale> #include <codecvt>
A more complete example available here: http://en.cppreference.com/w/cpp/locale/wstring_convert/from_bytes
1.4m articles
1.4m replys
5 comments
56.9k users