首页 > 解决方案 > 将多字节存储到 char 数组中

问题描述

以下代码有效:

char *text = "中文";
printf("%s", text);

然后我试图通过它的unicode代码点打印这个文本,它是0x4e2d“中”和0x6587“文”: 在此处输入图像描述

当然,没有打印出来。

我试图了解当我将多字节字符串存储到这里时发生了什么char*以及如何使用它的 unicode 代码点打印多字节字符串,此外,“ Format specifier '%ls' requires 'wchar_t *' argument instead of 'wchar_t *'”是什么意思?

谢谢你的帮助。

编辑:我在 Mac osx (high sierra 10.13.6) 和 clion 在此处输入图像描述

$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix

标签: cunicode

解决方案



推荐阅读