如何在C中使用Unicode区块?
我想在我的 C 程序中使用 unicode 块将它们显示在控制台中,例如 ▇、░ 等。但是,每当我尝试对 unicode 字符使用转义序列时,我只会收到奇怪的字母,例如:
printf("/u259A"); //259A is the unicode for ▚
Output: ÔûÜ
我查找了如何包含 unicode 字符,然后尝试使用 wchar_t:
#include <locale.h>
#include <stdio.h>
int main(int argc, char const *argv[]) {
setlocale(LC_ALL, "");
wchar_t c = "\u259A";
printf("%c",c);
return 0;
}
但这只给了我 ☺
作为输出而不是▚。删除 setlocale()
会给我一个空白输出。我不知道从现在开始该做什么。我唯一看到的是使用 printf("\xB2");
,它给了你▓
。但我不明白 B2
来自哪里或它代表什么。
I want to use unicode blocks in my C program to display them in the console like ▇, ░ and so on. However, whenever I try to use the escape sequence for unicode characters, I only get weird letters like:
printf("/u259A"); //259A is the unicode for ▚
Output: ÔûÜ
I looked up how to include unicode charactes then tried to use wchar_t:
#include <locale.h>
#include <stdio.h>
int main(int argc, char const *argv[]) {
setlocale(LC_ALL, "");
wchar_t c = "\u259A";
printf("%c",c);
return 0;
}
but that only gave me ☺
as the output instead of ▚. Removing setlocale()
would give me a blank output. I dont know what do to from this point on. The only thing I saw was using printf("\xB2");
which gave you ▓
. But I dont understand where the B2
comes from or what it stands for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,对我有用的是:
函数
_SETMODE()
显然是用于在U16文本编码上设置控制台。wprintf()
允许您打印宽字符(unicode同样)。l“”
在字符串向编译器指示之前,以下字符串是Unicode字符串。感谢大家的时间和答案!So what worked for me was the following:
the function
_setmode()
is apparently for setting the console on u16 text encoding.wprintf()
allows you to print wide characters (unicode aswell). TheL""
before the string indicates to the compiler, that the following string is a unicode string. Thanks to everyone for their time and answers!