Chinese characters printing issue under windows
Sam Hu
samhudotsamhu at gmail.com
Thu Dec 8 16:59:37 PST 2011
On Friday, 9 December 2011 at 00:51:35 UTC, Sam Hu wrote:
> For those who would like to print Chinese characters in windows
> console properly,below information for your easy reference.
>
> After test,write works properly all the way,writeln only works
> properly when the args is no less than 2.writefln works
> properly all the way.
>
> [code]
> module cnsetlocale;
>
> import core.stdc.wchar_;
> import core.stdc.locale;
>
> import std.stdio;
> import std.string;
> import std.conv;
>
>
> extern(C) int setlocale(int, char*);
static this() {
> fwide(core.stdc.stdio.stdout, 1);
> setlocale(0, cast(char*)"china"); }
int main(string[]
> args)
> {
> printf("你好DMD2!!\n");
> writefln("%s","你好DMD2!!");
> string msg="你好DMD2!!";
> string msg1="很好很好的同学";
> string msg2="大大的了不起!";
> writefln("the string is %s",msg);
> writefln("the string is %s \n %s\n%s
> and\n%s",msg,msg1,msg2,"很牛很牛");
>
> readln;
> return 0;
> }
> [/code]
printf("%.s\n",cnStr) works as well while printf(cnStr) does not.
Re-format the sample code:
module cnsetlocale;
import core.stdc.wchar_;
import core.stdc.locale;
import std.stdio;
import std.string;
import std.conv;
extern(C) int setlocale(int, char*); static this() {
fwide(core.stdc.stdio.stdout, 1);
setlocale(0, cast(char*)"china"); } int main(string[]
args)
{
printf("%*.s\n","你好DMD2!!\n");
write("你好DMD2!!\n");
writefln("%s","你好DMD2!!");
string msg="你好DMD2!!";
string msg1="很好很好的同学";
string msg2="大大的了不起!";
writefln("the string is %s",msg);
writefln("the string is %s \n %s\n%s
and\n%s",msg,msg1,msg2,"很牛很牛");
readln;
return 0;
}
More information about the Digitalmars-d
mailing list