How to print Chinese characters in console in window XP?

Sam Hu samhudotsamhu at gmail.com
Sat Jun 27 07:34:14 PDT 2009


Jarrett Billingsley Wrote:

> On Sat, Jun 27, 2009 at 5:53 AM, Sam Hu<samhudotsamhu at gmail.com> wrote:
> > In DMD2030 I just found that Chinese characters the like can not print properly into console.
> >
> > //Below code does not show output properly in windows console:
> > void main()
> > {
> > wstring country="Öйú";
> > writefln(country);
> > }
> >
> >
> >
> > Is this an OS issue or is there any way to reach the goal?
> 
> It's an OS issue.  Someone asks about this once every two weeks.  You
> have to set up cmd.exe to use Unicode.  You have to change the fonts
> to Lucida, I think, and use 'chcp 65001' before running your program.

Thanks so much for your help.
Below is my try:
1.source(wrote in notepad.exe)

module test;
import std.stdio;
import std.c.windows.windows;
extern(Windows) {BOOL SetConsoleOutputCP(UINT wCodePageID);}

void main()
{
SetConsoleOutputCP(65001);
wstring country="Öйú";
writefln(country);
}

2.set notepad font Lucida Console (acutally tried Lucida Sans Unicode also);
3.Save test.d in Unicode (actually also tried UTF-8);
4.Compile and run.But the output still doesn't make sense.

Regards,
Sam



More information about the Digitalmars-d-learn mailing list