#define testUnicode main
//Refer to https://www.qqxiuzi.cn/bianma/zifuji.php
//https://blog.csdn.net/hyongilfmmm/article/details/112045049
void testUnicode()
{
std::wstring a = L"汉"; //code point @ 0x6c49 ,a赋值的是unicode码点
unsigned char aa[10]; // code point @ 0x6c49 encoded in utf8 is 0xE6 B1 89
// in GB2312/GBK/GB18030 code is 0xBABA
WideCharToMultiByte(CP_UTF8, 0, a.c_str(), -1, (LPSTR)aa, 10, NULL, NULL);
unsigned char bb[10];
WideCharToMultiByte(CP_ACP, 0, a.c_str(), -1, (LPSTR)bb, 10, NULL, NULL);
std::cout <<"unicode code point,(No.) :" << std::hex << a.at(0) << std::endl;
std::cout << "unicode code point, encode using UTF8:" << std::hex << (int)aa[0] <<","<< (int)aa[1]<<","<< (int)aa[2]<<","<< (int)aa[3] << std::endl;
std::cout << "unicode code point, encode using ACP (GB2312/GBK/GB18030):" << std::hex;
std::cout << (int)bb[0] << "," << (int)bb[1] << "," << (int)bb[2] << "," << (int)bb[3] << std::endl;
}
输出:
unicode code point,(No.) :6c49
unicode code point, encode using UTF8:e6,b1,89,0
unicode code point, encode using ACP (GB2312/GBK/GB18030):ba,ba,0,cc