我编写此代码是为了打印 UTF-8 多字节字符串。但它无法正确打印。注意:我是在Linux系统中进行的。
#include <stdio.h>
#include <locale.h>
int main()
{
char *locale = setlocale(LC_ALL, "");
printf("\n locale =%s\n", locale);
printf("test\n \x263a\x263b Hello from C\n", locale);
return 0;
}
最佳答案
使用\u
代替\x
:
#include <stdio.h>
#include <locale.h>
int main()
{
char *locale = setlocale(LC_ALL, "");
printf("\n locale =%s\n", locale);
printf("test\n \u263a\u263b Hello from C\n");
return 0;
}
它运行并产生以下输出:
$ gcc foo.c
$ ./a.out
locale =C
test
☺☻ Hello from C
关于c - 在C中打印UTF-8多字节字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58039815/