我正在尝试将 Unicode 代码点存储在 C 中的变量中。我尝试使用 wchar_t
,但是由于我尝试存储的 Unicode 代码点是 U+1F319,它不适合wchar_t
。我该如何解决这个问题?我使用的是 Windows 计算机。
#include <locale.h>
#include <wchar.h>
#include <stdio.h>
#include <stdlib.h>
int main(void){
setlocale(LC_ALL,"en_US.UTF-8");
unsigned long long x = 0x1F319;
wchar_t wc =L'\U0001f319';
wprintf(L"%lc",wc);
return EXIT_SUCCESS;
}
下面的代码给出了这个错误:
Unicode.c:12:14: warning: character constant too long for its type
wchar_t wc =L'\U0001f319';
最佳答案
How can I store a unicode in C?
从 C11 开始,“存储 Unicode 代码点”,使用 char32_t
@Shawn
#include <uchar.h>
char32_t ch1 = 0x1F319;
char32_t ch2 = U'\U0001f319';
适用于我的 Windows 计算机。 ref
char32_t
which is an unsigned integer type used for 32-bit characters and is the same type as
uint_least32_t
... C11 §7.27 2
关于c - 如何在 C 中存储 unicode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53788749/