wchar_t的解释可以看这里:这里

程序和解析:

 1 # include<stdio.h>
 2 # include<stdlib.h>
 3 # include<locale.h>//设置本地化
 4 int main()
 5 {
 6     //常规的输出汉字
 7     char s[100] = "我是大好人";
 8     printf("%c%c\n", s[0], s[1]);
 9 
10 
11     //不合法输出,ascii中没有汉字,char只能输出字母,数字,字符
12     char x = '';
13     printf("%c\n", x);
14 
15 
16     //用wchar_t  存储宽字符
17     wchar_t ch = L'';//宽字符
18     printf("%d", sizeof(ch));
19     setlocale(LC_ALL, "chs");//简体中文
20     wprintf(L"\n %wc", ch); //汉字当作一个字符
21     wchar_t str[100] = L"我是一个好人";
22     wprintf(L"\n %s \n", str);
23     system("pause");
24 }
View Code

相关文章:

  • 2022-12-23
  • 2021-12-27
  • 2021-09-18
  • 2022-02-23
  • 2021-07-11
  • 2021-11-04
  • 2022-01-26
  • 2021-10-06
猜你喜欢
  • 2021-06-28
  • 2021-08-24
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
  • 2021-08-07
相关资源
相似解决方案