wcout显示中文

#inlcude <tchar.h>
#include <locale>
................
    char czz[101]="Begin被替换End";
    wchar_t wt[100];
    wstring strTarget = L"中文";
    wstring str2=L"y真是折腾人阿!!!";
    locale loc(""),oldloc;
    oldloc=wcout.imbue(loc);//设置
    wcout << strTarget<<endl;             
    wcout<<str2.c_str()<<endl; 
    wcout.imbue(oldloc);      //用完恢复 

    setlocale(LC_ALL,"");     //设置本地默认
    lstrcpy(wt,str2.c_str()); 
    wcstombs(czz,str2.c_str(),sizeof(czz));
    setlocale(LC_ALL,"C");     //用完恢复  
    cout<<czz<<endl;

   strcpy(czz,"Begin被替换End");
   setlocale(LC_ALL,"");     //设置本地默认
   wcstombs(czz,wt ,sizeof(czz));
   setlocale(LC_ALL,"C");     //用完恢复  

   cout<<czz<<endl;
................
 


也可以简单一点:

wchar_t *sss;

   setlocale(LC_ALL, "");

   sss=_T("aa我是aa");

   wcout<<sss<<"   "<<sizeof(sss)<<endl;

你可能感兴趣的:(wcout显示中文)