您必须首先选择正确的区域设置:
#include <locale.h>
setlocale(LC_ALL, "C.UTF-8");
Run Code Online (Sandbox Code Playgroud)
或者
setlocale(LC_ALL, "en_US.UTF-8");
Run Code Online (Sandbox Code Playgroud)
然后使用printforfprintf的格式%lc:
printf("%lc", UINT32_T_VARIABLE);
Run Code Online (Sandbox Code Playgroud)
这仅适用于足够小的 Unicode 代码点以适合wchar_t. 对于更完整和可移植的解决方案,您可能需要自己实现 Unicode 到 UTF-8 的转换,这并不是很困难。