APP NEWS

linux控制台显示中文

#include<stdio.h>#include<wchar.h>#include<locale.h>intmain(){#ifdef_WIN32setlocale(LC_ALL,"chs");#elsesetlocale(LC_ALL,"zh_CN.UTF-8");#endifwchar_tKZg[]=

2015-06-28 00:000 次阅读
linux控制台显示中文

  #include

  #include

  #include

  int main()

  {

  #ifdef _WIN32

  setlocale(LC_ALL, &chs&);

  #else

  setlocale(LC_ALL, &zh_CN.UTF-8&);

  #endif

  wchar_t KZg[] = {0x6211, 0};

  char buf[10] = {0};

  wcstombs(buf,KZg,10);

  printf(&_%s_n&,buf);

  }

  wchar_t 在linux上是4个字节, 在win32上是2个字节, MinGW也是2个字节.

  一般会节省空间使用utf-16.

  #ifdef _WIN32

  typedef wchar_t uchar;

  #else

  typedef unsigned short uchar; // 就不能使用string.h提供的宽字符串方法了.

  #endif

  linux上使用string常量只能用{}.

关键词标签:linux控制台显示中文

YOU MAY ALSO LIKE

更多应用推荐

浏览应用库