鉴于 UTF-16
,我想在控制台上打印一封孟加拉语字母该字母的低 2 个字节存储在 unsigned short
中变量。
例如,对于字母 অ
(引用:অ)
unicode 值为 - 0985(十六进制)
我有,unsigned short unicodeChar = 0x0985;
现在,我该如何打印这封信 অ
使用 unicodeChar
的值?
注意:我试过了- cout << "\u0985";
并打印出 অ
但我希望能够打印由变量 unicodeChar
表示的字符
最佳答案
尽量使用const char*来存储值。
#include <iostream>
using namespace std;
int main()
{
const char* uC = "\u0985";
cout << uC << endl;
}
如果想使用unsigned short的值,可以使用setlocale
,通过%lc
打印:
#include <stdio.h>
#include <locale.h>
int main()
{
if (!setlocale(LC_CTYPE, ""))
{
fprintf(stderr, "Error:Please check LANG, LC_CTYPE, LC_ALL.\n");
return 1;
}
unsigned short unicodeChar = 0x0985;
printf ("%lc\n",unicodeChar);
}
关于C++ : Print value of unsigned short variable as unicode character,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26325227/