Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 04, 2011 Asian characters are not printed propely in console | ||||
---|---|---|---|---|
| ||||
Attachments: | I'm sorry for posting in the wrong place. I attached screenshot of my code and the result. As you can see, Korean letters get changed after compilation. This problem doesn't happen with user input(from readln() method). Should I use different type and prefix or suffix similary to C++? |
January 04, 2011 Re: Asian characters are not printed propely in console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jun | On Tue, 04 Jan 2011 11:47:32 +0200, Jun <blings@naver.com> wrote: > Should I use different type and prefix or suffix similary to C++? Place the following code anywhere at the top level in your program: version(Windows) { import std.c.windows.windows : SetConsoleCP, SetConsoleOutputCP; static this() { SetConsoleCP(65001); SetConsoleOutputCP(65001); } } This code should really be in the standard library, I think. -- Best regards, Vladimir mailto:vladimir@thecybershadow.net |
January 05, 2011 Re: Asian characters are not printed propely in console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jun | On 04.01.2011 10:47, Jun wrote:
> I'm sorry for posting in the wrong place.
>
> I attached screenshot of my code and the result.
>
> As you can see, Korean letters get changed after compilation.
>
> This problem doesn't happen with user input(from readln() method).
>
> Should I use different type and prefix or suffix similary to C++?
If you save the file as utf-8, and set the console to CP 65001 (which is utf-8), it should work. Providing your console font suppports the characters, of course.
You can add the suffixes 'w' or 'd' to get utf-16 or utf-32, respectively. But then you need to save the file in that encoding, and change the console code page accordingly. It all has to match up.
But I would expect it to work with other character sets too, as long as the file encoding and the console match.
|
January 05, 2011 Re: Asian characters are not printed propely in console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vladimir Panteleev | Vladimir Panteleev:
> This code should really be in the standard library, I think.
File a bug report, with a little patch, then :-)
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation