如何在Windows控制台上显示中文

来源:互联网 发布:网络语安利是什么意思 编辑:程序博客网 时间:2024/04/19 15:29

准备把服务器端的程序采用UNICODE 来编写

编译ACE的时候,我增加了

#define ACE_HAS_WCHAR

#define ACE_USE_WCHAR

编写一个Hello world的小程序,结果运行发现在控制台上显示不出中文,很快发现在原来需要设置console的属性才能让UNICODE字符正常显示出来。

 

代码如下

 

include "stdafx.h"
#include "ace/os.h"
#include "ace/Log_Msg.h"
#include <mmsystem.h>
#include <locale.h >
int _tmain(int argc, _TCHAR* argv[])
{
 setlocale(LC_ALL,"CHS"); //****** 设置本地属性*********
 for(int i = 0; i < 100; i++) 
 {
    int cur = ACE_OS::gettimeofday().msec();
    _tprintf(ACE_TEXT("Hello world,今天您UNICODE了吗? [%d]/n"),cur);
    OutputDebugStr(ACE_TEXT("Hello world,今天您UNICODE了吗?/n"));
    ACE_DEBUG((LM_INFO,ACE_TEXT("Hello ACE,今天您UNICODE了吗?/n")));
    ACE_OS::sleep(1);
 }
 return 0;
}