Windows 8 x64; Visual Studio 2012;Unicode字符在控制台通过C++
我通过本书学习C++。在这个论坛上,我发现了many themes关于读\写Unicode字符串通过C++。但是这个主题没有被标记为解决(???)。在C++中它真的是个大问题吗?我曾尝试不同的变体 - 他们不工作对我说:
#include<iostream>
#include<Windows.h>
#include <io.h>
#include <fcntl.h>
using namespace std;
int main() {
// variant 1:
wcout << L"Hello World!" << endl; // displayed
wcout << L"Привет Мир!" << endl;// not displayed
//**********************************************
// variant 2:
SetConsoleOutputCP(CP_UTF8);
wchar_t s[] = L"Hello World (2)!";
int bufferSize = WideCharToMultiByte(CP_UTF8, 0,
s, -1, NULL, 0, NULL, NULL);
char* m = new char[bufferSize];
WideCharToMultiByte(CP_UTF8, 0, s, -1, m,
bufferSize, NULL, NULL);
wprintf(L"%S", m); // valid output
wcout << endl;
printf("%s", m); // valid output
wcout << endl;
wchar_t s2[] = L"Привет мир (2)!";
int bufferSize2 = WideCharToMultiByte(CP_UTF8, 0,
s2, -1, NULL, 0, NULL, NULL);
char* m2 = new char[bufferSize2];
WideCharToMultiByte(CP_UTF8, 0, s2, -1, m2,
bufferSize2, NULL, NULL);
wprintf(L"%S", m2); // invalid output
wcout << endl;
printf("%s", m2); // invalid output
wcout << endl;
//**********************************************
// variant 3 (not working):
_setmode(_fileno(stdout), _O_U16TEXT);
wcout << L"Testing unicode -- English -- Ελληνικά"
<< "-- Español." << endl;
return 0;
}
但它为英文字符只有... 屏幕:
我怎样才能解决这个问题到C++的问题?
偏离主题,但你怎么能让Windows 8的窗口拐角曲线那样 –