IT猫扑网文章教程

分类分类

linux控制台显示中文

2015-06-28 00:00作者:网管联盟

  #include <stdio.h>

  #include <wchar.h>

  #include <locale.h>

  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常量只能用{}.

展开全部

相关文章

说两句网友评论
    我要跟贴
    取消