在Windows控制台应用程序中输出Unicode字符串
SetConsoleOutputCP(CP_UTF8);wchar_t s[] = L"èéøÞǽлљΣæča";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);
SetConsoleOutputCP(CP_UTF8);utf8_locale = locale(old_locale,new boost::program_options::detail::utf8_codecvt_facet()); wcout.imbue(utf8_locale);wcout << L"¡Hola!" << endl;
编辑
//Unicode output for a Windows console ostream &operator-(ostream &stream, const wchar_t *s) {
int bufSize = WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL);
char *buf = new char[bufSize];
WideCharToMultiByte(CP_UTF8, 0, s, -1, buf, bufSize, NULL, NULL);
wprintf(L"%S", buf);
delete[] buf;
return stream; } ostream &operator-(ostream &stream, const wstring &s) {
stream - s.c_str();
return stream; }慕无忌1623718
偶然的你
慕虎7371278