Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wprintf with UNICODE (Hebrew) characters

I have a wchar_t array with English and Hebrew characters and when I print it with wprintf() it prints to console the English characters only. When I'm using _wsetlocale( LC_ALL, L"Hebrew" ) I get the Hebrew characters as "????". The machine I'm working on supports Hebrew of course.

BTW - using c:\windows\system32\cmd.exe and 'dir' on a directory with Hebrew characters, also shows "???" instead of Hebrew.

Any idea?

like image 827
Elad Avatar asked Jan 05 '12 15:01

Elad


2 Answers

Have you confirmed that your console font can handle unicode characters? Most don't. You might try the Consolas font.

When I've run into this before, I've found this article by Michael Kaplan to be extremely helpful.

like image 116
ReinstateMonica Larry Osterman Avatar answered Sep 22 '22 16:09

ReinstateMonica Larry Osterman


Basically Microsoft's C runtime library isn't implemented very well to allow this.

You can do _setmode(_fileno(stdout), _O_U16TEXT); and then writing with wcout or wprintf will work. However trying to use cout or printf, or anything that doesn't write UTF-16 will then cause the program to crash.

like image 38
bames53 Avatar answered Sep 21 '22 16:09

bames53