Re: outputting Unicode to console



Hi Henry!

I need to use low-level I/O such as write() to print some messages to stdout. However, when the program is compiled to use wide chars the printed output is correspondingly wide!

As long as you only want to display ASCII chars, I would not recommend to use UNICODE in console apps...


If you want to display other chars (like chineese) you need to be aware of the following:
- your console must have a appropriate font which can display the chars (glyphs); the normal (default) font is not able to do this.
- if you use functions like "wprintf/wcout", it is not possible to display unicode-charachers (see: wprintf/wcout has no UNICODE support http://blog.kalmbachnet.de/?postid=23 http://blog.kalmbachnet.de/?postid=5)
- if you use native functions like write, then this uses internally WriteFile with which is also not possible to output unicode characters...
- to output unicode characters you need to use WriteConsoleW (http://msdn.microsoft.com/library/en-us/dllproc/base/writeconsole.asp)




Do I have to go through the WideCharToMultiByte() process for each message or is there a cleaner solution?

If you just want to display ANSI/ASCII-characters this one solution...

An other would be:
<code>
wchar_t wbuf[] = L"HI THERE\n";
printf("%S", wbuf);
</code>

--
Greetings
  Jochen

   My blog about Win32 and .NET
   http://blog.kalmbachnet.de/
.



Relevant Pages

  • Re: CFile ops using char or TCHAR
    ... >just noticed that my file handling class is working chars not TCHARs. ... >Do I need to be working in wide chars for CFile operations, ... you need to use the type of characters you want ... CE is heavily biased towards UNICODE. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Unicode & Pythonwin / win32 / console?
    ... > * Webbrowsers for example have to display defective HTML as good as ... unknown unicode chars as "?" ... > occasionally chinese chars are displayed cryptically on non-chinese ... If the decision for default 'strict' encoding on ...
    (comp.lang.python)
  • Re: Fedora, unicode, console
    ... > to get UTF-8 enabled in console? ... *all* the Unicode characters: Fedora has chosen a good one, ... > has not all UTF-8 chars, ... Well, in vim, if you know the Unicode reference, try ...
    (Fedora)
  • Re: Unicode problem in ucs4
    ... Unicode object to a wchar_t representation. ... You also have to allocate the buffer to store the wchar_t data in. ...    most size wchar_t characters are copied. ... chars are copied to sample ...
    (comp.lang.python)
  • Unicode y Delphi
    ... I have an app that sends chars to the active app that works fine ... Where can I read up on Unicode? ... relationship between Unicode and WideChars. ...
    (comp.lang.pascal.delphi.misc)