#include <stdio.h>
#include <locale.h>
int main()
{
const char str[] = "这里全是中文"
printf("\n输出字符数:%d\n", printf(str))
puts(str)
return 0
}2、单个中文字符,需要进行本地化设置,需要使用宽字符版的printf()即wprintf输出。
#include <stdio.h>
#include <locale.h>
int main()
{
setlocale(LC_ALL, "chs")
wchar_t wc = L'中'
wprintf(L"%c\n",wc)
return 0
}
1、首先,打开C语言编译器,新建一个初始.cpp文件,例如:test.cpp。
2、在test.cpp文件中,输入C语言代码:char a[] = "中文"puts(a) 。
3、编译器运行test.cpp文件,此时成功定义了中文并进行了输出。