简体   繁体   中英

How to use the new char16_t and u8 types?

c11 improve encoding support with built-in types for utf-8 utf-16 and utf-32.

However I was completely unable to find reference on using them in Standard functions. All I found is how to use them in c++11 not in C.

So how to printf a char32_t for example?

There isn't much to say: C11 only introduced four new standard library functions for working with char16_t and char32_t , which convert them to/from multibyte strings:

With respect to printf() , they behave like uint_least16_t and uint_least32_t types, so you can use the same format specifiers for them:

#include <inttypes.h>

char32_t x = ...;
printf("%" PRIuLEAST32 "\n", x);

If you want to print the value as a character , you will need to use the conversion functions above.

Working with char16_t and char32_t character and string literals is identical in both C11 and C++11.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM