你如何在C++中使用Unicode?
我知道有wchar_t
和wchar_t*
,但我想知道如何仅使用Unicode值进行赋值,类似于将变量与ASCII值相等来赋值字符的方式:
char a = 92;
我正在使用MinGW编译器,如果有区别的话。
它可以非常简单,例如:
wchar_t a=L'a';
wchar_t hello_world[]=L"Hello World";
// Or if you really want it to be (old school) C++ and not C
std::wstring s(L"Hello World");
// Or if you want to (be bleeding edge and) use C++11
std::u16string s16(u"Hello World");
std::u32string s32(U"Hello World for the ∞ᵗʰ time");
完全相同的方式:
wchar_t a = 97;
wchar_t xi = 0x03be; // ξ
int
告诉我们它是一个没有小数部分的数字。然而,你可能在谈论十进制数,将十六进制(基数16)转换为十进制数。 - Tommy Andersen