views:

397

answers:

3

For example, if I write:

cout << "Привет!" << endl; //it's hello in Russian

in console it would be something like "╧ЁштхЄ!"

ok, I know that we can use:

setlocale(LC_ALL, "Russian");

but after that not working command line arguments in russian (if I start my program through BAT file):

StartProgram.bat

chcp 1251
MyProgram.exe -user=Олег -password=Пароль

so, after setlocale program can't read russian arguments properly.

This happens because BAT file in CP1251, but console is in CP866

So, there is a question:

How to write in C++ console russian text and same time russian command line arguments have to be read properly

thanks

+2  A: 

See this entry from Michael Kaplan's blog: http://blogs.msdn.com/michkap/archive/2008/03/18/8306597.aspx

Nemanja Trifunovic
Thanks, it works!But in this way I can't use cout, only wprintf
VextoR
`wcout` is the equivalent of `wprintf` just like `cout` is the equivalent of `printf` - the last two won't do Unicode.
MSalters
+4  A: 

Have you tried using wcout? It is similar to cout, but it accepts "wide" characters, which should permit the proper unicode encodings.

This article about localization, and another, both from MSDN may be of use.

e.James
unfortunately wcout not working also. I don't use unicode
VextoR
Unless I am completely mistaken, unicode will be a necessity for cyrillic. Regular 8-bit ASCII does not have glyphs for most of the characters in the cyrillic alphabet. The console output from your example (`╧ЁштхЄ`) is composed of some exotic 8-bit ASCII characters because the correct characters aren't available in that encoding.
e.James
Hmm.. Windows cyrillic is 1251 (Windows-1251) codepage. But DOS cyrillic uses 866 codepage.So, "Привет!" in CP1251 = "╧ЁштхЄ!" in CP866.This is what happened, I write in C++ as cp1251, but console shows it as cp866.
VextoR
Ah, the joys of character encodings :)
e.James
Don't forget if you're using wcout to put `L` in front of all your literals. Therefore, `wcout << L"Привет!" << endl;` in your example.
Billy ONeal
thanks, but this not working too, I think because I don't use Unicode
VextoR
@VextoR: start using it. Look at MichKap's blog again (see other link) - Microsoft "supports" 8 bit encodings for _legacy_ reasons. In particular, they are unlikely to change things, even when you'd consider them bugs - changing them would risk breaking the old programs, without any benefit for the newer Unicode apps.
MSalters
A: 

Have you set the language for non-unicode programs to be Russian, in the Regional and Language Options section of the Control Panel?

(I have no idea what the usual setup for Russian-speaking programmers might be; I just wonder whether it is common to set this to some kind of English to avoid confusing overly-parochial tools.)

Unless my memory is playing tricks, when I was working with some code from Japanese developers it was this step that got the console displaying non-Unicode Japanese text (Shift-JIS encoding) properly.

brone