How to write Cyrillic text in C++ console

c++, character-encoding, encoding

Solution

See this entry from Michael Kaplan's blog:

http://www.siao2.com/2008/03/18/8306597.aspx

Problem

For example, if I write: ``` cout << "Привет!" << endl; //it's hello in Russian ``` In the console it would be something like `╧ЁштхЄ!`. OK, I know that we can use: ``` setlocale(LC_ALL, "Russian"); ``` But after that, command line arguments in Russian do not work (if I start my program through a BAT file): StartProgram.bat ``` chcp 1251 MyProgram.exe -user=Олег -password=Пароль ``` So, after `setlocale` the program can't read Russian arguments properly. This happens because the BAT file in CP1251, but the console is in CP866. So, there is a question: How can I write Russian text in the C++ console and at the same time have Russian command line arguments read properly.

Original source