[英]C/C++ how to reading const char for UNICODE?
#include <iostream>
#include "windows.h"
void main()
{
printf("0x%x", '가');
system("pause");
}
The result of this code is "0xB0A1" (CP949) This is what I want "0xAC00" (UNICODE) 该代码的结果是“ 0xB0A1”(CP949),这就是我想要的“ 0xAC00”(UNICODE)
i tried project Configuration Properties character set changed to UNICODE but Still not working 我尝试将项目配置属性字符集更改为UNICODE,但仍然无法正常工作
I would really appreciate it if you could give me some help. 如果您能给我一些帮助,我将不胜感激。 thank you 谢谢
'가'
is a multi-character character constant that doesn't fit in a single char. '가'
是一个多字符字符常量,不适用于单个字符。 You would need to use wchar_t
defined in stddef.h
. 您将需要使用stddef.h
定义的wchar_t
。 See also wchar.h
. 另请参见wchar.h
。
So if you want the unicode value for that: 因此,如果您想要unicode值:
#include <stdio.h>
#include <stddef.h>
int main(void)
{
wchar_t wide = L'가';
printf("Unicode: 0x%X\n", wide);
return 0;
}
This prints: 打印:
Unicode: 0xAC00
However, if you do wchar_t wide = '가';
但是,如果您执行wchar_t wide = '가';
, you get a warning and when you run this, it prints 0xEAB080
which is the UTF8 bytestring. ,您将收到一条警告,并且在运行此警告时,它会打印0xEAB080
,它是UTF8字节0xEAB080
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.