c - 如何在 C 中存储 unicode?

标签 c unicode wchar-t

我正在尝试将 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/

相关文章:

c - 文本文件中的无效本地化字符

Python:将 Unicode 转换为 ASCII,对于 CSV 文件没有错误

c++ - 如何将动态字符串转换为 wchar_t 以更改背景

ios - setlocale() 在 iOS 模拟器中不起作用?

c - 指向 C 中指针的指针未按预期工作

将 C 字符串转换为二进制表示

c - C中额外大括号的实际使用

python - 将非 ascii 字符分配给 python 内置字符串时,该值意味着什么?

php - wchar_t 到 PHP UTF8 文件

c - 数组中具有相同顺序的序列 - 识别序列