如何在 C 中存储 unicode?
How can I store a unicode in C?
我正在尝试将 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
#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
我正在尝试将 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
#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