Writing unicode strings to the console

Adam D. Ruppe destructionator at gmail.com
Mon Dec 17 17:18:31 PST 2012


On Tuesday, 18 December 2012 at 00:59:12 UTC, Jeremy DeHaan wrote:
> How/Where would I call this?

Right at the beginning of your main, but after trying it, I don't 
think this is going to fix your problem anyway... I think it is 
fonts. But:

import std.stdio;

extern(Windows) int SetConsoleOutputCP(uint);

void main() {
     if(SetConsoleOutputCP(65001) == 0)
         throw new Exception("failure");
     string String = "さいごの果\“hello\”";

     writeln(String);
}


Is how you'd use it. But I just tried on my Windows 7 computer, 
and the default was utf8, so the call was unnecessary. You can 
try though and see what happens.

A problem I did have though was my console font didn't support 
unicode. If you bring up the properties option on the console 
window, under the Font tab, you can pick a font.

Raster fonts is what mine was set to, and had no unicode support. 
It output gibberish.

Lucida Console gave better results - it had the right number of 
characters and showed the curly quotes, but not the other 
characters. Could be because I only have the English language 
pack for Windows installed on my computer.

But anyway I suggest you try playing with the different fonts you 
have and see what happens.


More information about the Digitalmars-d-learn mailing list