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:
char16_t
: mbrtoc16()
and c16rtomb()
char32_t
: mbrtoc32()
and c32rtomb()
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.