将特殊字符串转换为 std::wstring c++

问题描述 投票:0回答:1

我定义了一个

const char* s = "\u0633\u0644\u0627\u0645"
,它应该被翻译为
std::wstring
L"سلام"
。我该如何执行此转换?换句话说,我需要类似于此网站的内容,其中提供了以下屏幕截图:

可以看出,该术语被解码为

سلام
。我想编写 C++ 代码来执行相同的解码。

c++ decode utf-16
1个回答
0
投票

一种解决方案是使用 codecvt,尽管它已被弃用。

#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;
}
© www.soinside.com 2019 - 2024. All rights reserved.