使用wchar_t输入,显示中文

上机环境 win7 vs2008 基于c++,C语言同样可以通过下列代码

  • 但凡涉及中文,都要包含locale.h头文件
  • setlocale(LC_CTYPE, "chs");设置本地环境为中文
  • 代码
#include<stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <locale.h>

int main()
 {
     wchar_t words[12];
     setlocale(LC_CTYPE, "chs");
     /*wchar_t zi =L'喜';*/
     words[0]=L'';
     words[1]=L'';
     words[2]=L'';
     words[3]=L'';
     words[4]=L'';
     words[5] ='\0';
     //wprintf(L"%c\n",zi);
     wprintf(L"%s\n",words);
     system("pause");
     return 0;
 }

 

  •  无论.c或者 .cpp都能通过

 

posted @ 2020-03-18 20:17  saintdingtheGreat  阅读(1180)  评论(0编辑  收藏  举报