1

I need to storage some Unicode character using a format like '\uxxxx'.(e.g.\u6D4B). But I can't convert it back to text. I'm using UTF-16, not UTF-8.The way that works on UTF-8 will decode into a wrong character. I tried many ways but they all falied. So I want to know if there a way to do such convertion using C++. No matter using Windows API or boost library or something else.

This is the function I wrote:

CString Decode(CString mark)
{
    int chrnum;
    sscanf(CStringA(mark).GetBuffer(), "\u%X", &chrnum);
    mark.Format(L"%X", chrnum);
    unsigned int chr = std::stoul(CStringA(mark).GetBuffer(), nullptr, 16);
    wchar_t wchr[2] = { boost::numeric_cast<wchar_t>(chr) ,L'\000' };
    mark = CString(wchr);
    return mark;
}

But it outputs nothing.

My encode function as follows:

CString Encode(TCHAR chr)
{
    int recv = static_cast<int>(chr);
    CString ret;
    ret.Format(L"\\u%5X", recv);
    return ret;
}

Here is an example:

Input: \u6D4B

Output:

0 Answers0