#include <stdio.h>
int main(int argc, char const *argv[])
{
printf("%lc" , L'人');
return 0;
}
此外,我还注意到 cppreference 上对C标准库 printf() 函数占位符 %lc 的描述:
这个要看你的编译器支持,试试看
wchar_t ch = _T('人');
printf("%lc" , ch);
你需要
#include < locale.h>
然后在程序开头加上
setlocale(LC_ALL, "chs");
就行了。完整代码如下:
#include < stdio.h>
#include < locale.h>
int main()
{
setlocale(LC_ALL, "chs");
printf("%lc", L'人');
return 0;
}
#include <stdio.h>
int main(int argc, char **argv)
{
printf("%s" , "人");
return 0;
}
这样子你可以试一下,反正我是成功了。
%s代表C风格String,即char*。
一个中文字是两个字节,不能算一个字符,只能当字符串。
若有帮助,请采纳,谢谢!