Cyrillic in console
Is there any way to write cyrillic text in console window? If it is OS dependent I want to know how at least under Windows.
[123 byte] By [
T.G.] at [2007-11-19 7:28:50]

# 1 Re: Cyrillic in console
You may go for the wstring ...
// compile with: /EHsc
#include <string>
#include <iostream>
using namespace std;
int main( )
{
wstring s2 ( L"my unicode string" );
cout << s2 << endl;
return 0;
}
Use the escape sequences to bring a kyrilic character (as hex code) into your string
wchar_t wchar = L'\x8119'; // Or another hex code
# 2 Re: Cyrillic in console
The characters will only show correctly if your console font is set to a Cyrillic encoding (e.g. Windows - Cyrilic). On most Unix systems the console can be turned into a UTF-8 mode these days (and many times that's done by default), so it's easier than on Windows.
The way to do it for windows is to use SetConsoleCP with a cyrillic codepage, so most probably 1251.
# 3 Re: Cyrillic in console
Thanks for the replies. I tried to compile NoHero's code but couldn't succeed. Complaining "there is no reasonable operator << between cout and wstring". It seems there is std::wcout but when I use it the compiler is saying "wcout undeclared". Any idea?
T.G. at 2007-11-9 0:44:30 >

# 4 Re: Cyrillic in console
Could you give me a clue how to turn a unix console into UTF8 mode?
T.G. at 2007-11-9 0:45:27 >

# 5 Re: Cyrillic in console
Just want to bring it to your attention :-)
T.G. at 2007-11-9 0:46:37 >

# 6 Re: Cyrillic in console
What console are you using?
# 7 Re: Cyrillic in console
I use Sun Solaris system on SunBlade 150 in my office. On my laptop I use WinXP.
T.G. at 2007-11-9 0:48:31 >

# 8 Re: Cyrillic in console
Hum, sorry I don't have anyexperience with Solaris. It should be in the documentation though.
Have you tried setting the console codepage under windows the way I proposed? To actually output the characters, you can just use the characters directly from the codepage (no need for using Unicode here).
# 9 Re: Cyrillic in console
Yes. SetConsoleCP was for input encoding, and SetConsoleOutputCP was for output encoding. I had to change the console font to "Lucida Console" by hand. Now it is printing OK. Thank you very much.
But I have stille a questioin. Even though I changed the input code page to 1251, I can not enter cyrillic characters from keyboard (in console, and of course the proper keyboard driver is installed). And the console has only two fonts available, namely "raster font" and "Lucida console". How can one use other fonts? do you know an API function to change console font?
T.G. at 2007-11-9 0:50:31 >

# 10 Re: Cyrillic in console
As non-portable simple way out, I use CharToOem() function on string before outputing it when everything in the system (Windows) set to Cyrillic...