Sono in fase di apprendimento di questo, quindi correggimi se ho qualcosa di sbagliato.
Sembra che questo è un processo in tre fasi:
- largo uso versioni di cout, cin, archi e così via. Quindi: wcout, wcin, wstring
- Prima di utilizzare un flusso, impostarlo su una modalità Unicode.
- Configurare la console di destinazione per utilizzare un font abilitato per Unicode.
Ora dovresti riuscire a scuotere quei funky åäös.
Esempio:
#include <iostream>
#include <string>
#include <io.h>
// We only need one mode definition in this example, but it and several other
// reside in the header file fcntl.h.
#define _O_WTEXT 0x10000 /* file mode is UTF16 (translated) */
// Possibly useful if we want UTF-8
//#define _O_U8TEXT 0x40000 /* file mode is UTF8 no BOM (translated) */
void main(void)
{
// To be able to write UFT-16 to stdout.
_setmode(_fileno(stdout), _O_WTEXT);
// To be able to read UTF-16 from stdin.
_setmode(_fileno(stdin), _O_WTEXT);
wchar_t* hallå = L"Hallå, värld!";
std::wcout << hallå << std::endl;
// It's all Greek to me. Go UU!
std::wstring etabetapi = L"η β π";
std::wcout << etabetapi << std::endl;
std::wstring myInput;
std::wcin >> myInput;
std:: wcout << myInput << L" has " << myInput.length() << L" characters." << std::endl;
// This character won't show using Consolas or Lucida Console
std::wcout << L"♔" << std::endl;
}
fonte
2013-03-16 12:26:34
Qual è il vostro font della console? Basta usare CMD.EXE per verificare. Differisce dalla versione di Windows alla versione e può essere personalizzato. – MSalters