c++中win32控制台輸出寬字元

來源:互聯網
上載者:User

也許控制台,很少使用輸出,或者說很少輸出漢字,

今天我就想輸出漢字,

可是發現控制台輸出寬字元有問題,

問高手,無果,高手說,這個沒辦法,不能輸出漢字

我就不信了,.

下面自己精心理解

我就不信這個事.,下面的代碼好好我讓他輸出寬字元,各種辦法

 

// FindFileTest.cpp : 定義控制台應用程式的進入點。
//

#include "stdafx.h"
#include <Windows.h>
#include <atlstr.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{

 /********方法1*******/
 char * str5="方法1";
 cout<<str5<<endl;
 wcout<<str5<<endl;
 /********方法2*******/
 string str2="方法2";
 cout<<str2.c_str()<<endl;
 wcout<<str2.c_str()<<endl;

 /**************
 寬位元組 字元的控制台輸出 添加下面轉化函數
 **************/
 locale loc("chs"); //定義“地區設定”為中文方式
 wcout.imbue(loc);  //載入中文字元輸入方式
 /********方法3*******/
 wstring str4=L"方法3";
 cout<<str4.c_str ()<<endl;
 wcout<<str4.c_str ()<<endl;
 /********方法4*******/
 wchar_t * str1=L"方法4";
    cout<<str1<<endl;
 wcout<<str1<<endl;
 /********方法5*******/
 CString str3="方法5";
 cout<<str3<<endl;
 wcout<<str3<<endl;

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.