c语言中如何打出中文?

Python0317

c语言中如何打出中文?,第1张

1、中文字符串可以使用printf()、puts()等函数直接输出。

#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

}

需要准备的材料分别有:电脑、C语言编译器

1、首先,打开C语言编译器,新建一个初始.cpp文件,例如:test.cpp。

2、在test.cpp文件中,输入C语言代码:char a[] = "中文"puts(a) 。

3、编译器运行test.cpp文件,此时成功定义了中文并进行了输出。