Namespaces
Variants

char8_t

From cppreference.net
ヘッダーで定義 <uchar.h>
typedef unsigned char char8_t ;
(C23以降)

char8_t はUTF-8用に使用される符号なし整数型であり、 unsigned char と同じ型です。

#include <stdio.h>
#include <uchar.h>
int main(void)
{
    char8_t str[] = u8"zß水🍌"; // or "z\u00df\u6c34\U0001f34c"
    size_t str_sz = sizeof str; // sizeof *str == 1 by definition
    printf("%zu UTF-8 code units: [ ", str_sz);
    for (size_t n = 0; n < str_sz; ++n)
        printf("%02X ", str[n]);
    printf("]\n");
}

出力例:

11 UTF-8 code units: [ 7A C3 9F E6 B0 B4 F0 9F 8D 8C 00 ]

参考文献

  • C23規格 (ISO/IEC 9899:2024):
  • 7.30 Unicodeユーティリティ <uchar.h> (p: 410)

関連項目

C++ documentation for Fundamental types
**日本語訳:**
C++ documentation for Fundamental types
**翻訳結果:** - "C++ documentation" → 「C++ ドキュメント」 - "for" → 「の」 - "Fundamental types" → 「基本型」 HTMLタグ、属性、C++固有の用語("C++ documentation"、"Fundamental types")は翻訳せず、元のフォーマットを保持しています。