本文目錄一覽:
c語言中如何打出中文?
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、引入標準輸入輸出庫:sdtio.h。
2、定義字元串形式的漢字(採用字元數組存儲)。
3、使用printf函數,或者puts函數輸出字元串形式的漢字。
例如:
#includestdio.h
int main()
{
char str[]=”輸出漢字”;
printf(“%s\n”,str);
puts(str);
return 0;
}
/*
運行結果:
輸出漢字
輸出漢字
*/
c語言怎樣才能輸出中文???(最簡單的方法)
定義一個字元串變數,在這個變數的值中就可以輸入中文了。漢字是多位元組的,一個char放不下,可以使用字元數組,但需要給數組分配空間,或者使用string。
例如:
#includestdio.h
int main(void)
{
char a[128];
printf(“請輸入所需輸出的漢字:”);
scanf(“%s”,a);
printf(“%s\n”,a);
return 0;
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/237756.html