Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write Cyrillic text in C++ console

Tags:

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.

like image 709
VextoR Avatar asked Feb 14 '10 15:02

VextoR


1 Answers

See this entry from Michael Kaplan's blog:

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

like image 84
Nemanja Trifunovic Avatar answered Sep 20 '22 13:09

Nemanja Trifunovic