也許控制台,很少使用輸出,或者說很少輸出漢字,
今天我就想輸出漢字,
可是發現控制台輸出寬字元有問題,
問高手,無果,高手說,這個沒辦法,不能輸出漢字
我就不信了,.
下面自己精心理解
我就不信這個事.,下面的代碼好好我讓他輸出寬字元,各種辦法
// 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;
}