converting special string to std::wstring c++

151 views Asked by At

I defined a const char* s = "\u0633\u0644\u0627\u0645" which should be translated to std::wstring as L"سلام". How can I perform this conversion? In other words, I need something similar to this web site, in which its screen shot has been provided below:

image

As it can be seen, the term is decoded to سلام. I want to write C++ code to perform this same decoding.

1

There are 1 answers

0
Finxx On

One solution is to use codecvt, though it is deprecated.

#include <codecvt>
#include <string>

int main() {
    const char* s = "\u0633\u0644\u0627\u0645";
    
    std::string ss = s;
    std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
    std::wstring ws = conv.from_bytes(ss);
    
    __debugbreak();
    
    return 0;
}