digitalmars.D.learn - How to write asia characters on console?
- Lave Zhang (15/15) Feb 07 2015 Hi,
- weaselcat (5/20) Feb 07 2015 Hi,
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (5/20) Feb 07 2015 This thread may be useful:
- Lave Zhang (17/40) Feb 08 2015 Thanks, my problem has been solved:)
- mzfhhhh (2/18) Feb 08 2015 This solution has a problem, look at this:
- FrankLike (48/63) Feb 12 2015 add such code is better than use 'chcp 65001' for exe's consumer.
Hi, My first D program is like this: ----------------------------------- import std.stdio; void main(string[] args) { dstring s1 = "hello你好"d; writeln(s1); } ----------------------------------- But the output is not correct(and my console codepage is 936): C:\D\dmd2\samples\d>dmd hello.d -offilename hello.exe C:\D\dmd2\samples\d>hello.exe hello浣犲ソ thanks.
Feb 07 2015
On Sunday, 8 February 2015 at 05:57:31 UTC, Lave Zhang wrote:Hi, My first D program is like this: ----------------------------------- import std.stdio; void main(string[] args) { dstring s1 = "hello你好"d; writeln(s1); } ----------------------------------- But the output is not correct(and my console codepage is 936): C:\D\dmd2\samples\d>dmd hello.d -offilename hello.exe C:\D\dmd2\samples\d>hello.exe hello浣犲ソ thanks.Hi, I tried your code and it works fine for me. I think the windows console only supports UTF-16, try using wchar/wstring instead of dchar/dstring.
Feb 07 2015
On 02/07/2015 09:57 PM, Lave Zhang wrote:Hi, My first D program is like this: ----------------------------------- import std.stdio; void main(string[] args) { dstring s1 = "hello你好"d; writeln(s1); } ----------------------------------- But the output is not correct(and my console codepage is 936): C:\D\dmd2\samples\d>dmd hello.d -offilename hello.exe C:\D\dmd2\samples\d>hello.exe hello浣犲ソ thanks.This thread may be useful: http://forum.dlang.org/thread/suzymdzjeifnfirtbnrc dfeed.kimsufi.thecybershadow.net#post-suzymdzjeifnfirtbnrc:40dfeed.kimsufi.thecybershadow.net Ali
Feb 07 2015
On Sunday, 8 February 2015 at 06:26:38 UTC, Ali Çehreli wrote:On 02/07/2015 09:57 PM, Lave Zhang wrote:Thanks, my problem has been solved:) --------------------------------------- import std.stdio; import core.stdc.wchar_; extern(C) int setlocale(int, char*); static this() { fwide(core.stdc.stdio.stdout, 1); setlocale(0, cast(char*)"china"); } int main(string[] args) { string s1 = "hello你好"; writefln("%s", s1); return 0; }Hi, My first D program is like this: ----------------------------------- import std.stdio; void main(string[] args) { dstring s1 = "hello你好"d; writeln(s1); } ----------------------------------- But the output is not correct(and my console codepage is 936): C:\D\dmd2\samples\d>dmd hello.d -offilename hello.exe C:\D\dmd2\samples\d>hello.exe hello浣犲ソ thanks.This thread may be useful: http://forum.dlang.org/thread/suzymdzjeifnfirtbnrc dfeed.kimsufi.thecybershadow.net#post-suzymdzjeifnfirtbnrc:40dfeed.kimsufi.thecybershadow.net Ali
Feb 08 2015
Thanks, my problem has been solved:) --------------------------------------- import std.stdio; import core.stdc.wchar_; extern(C) int setlocale(int, char*); static this() { fwide(core.stdc.stdio.stdout, 1); setlocale(0, cast(char*)"china"); } int main(string[] args) { string s1 = "hello你好"; writefln("%s", s1); return 0; }This solution has a problem, look at this: http://forum.dlang.org/thread/jfawjvoedsxsznsuejoh forum.dlang.org#post-tyslcbycorgfaqimldnd:40forum.dlang.org
Feb 08 2015
On Sunday, 8 February 2015 at 05:57:31 UTC, Lave Zhang wrote:Hi, My first D program is like this: ----------------------------------- import std.stdio; void main(string[] args) { dstring s1 = "hello你好"d; writeln(s1); } ----------------------------------- But the output is not correct(and my console codepage is 936): C:\D\dmd2\samples\d>dmd hello.d -offilename hello.exe C:\D\dmd2\samples\d>hello.exe hello浣犲ソ thanks.add such code is better than use 'chcp 65001' for exe's consumer. extern(C) int setlocale(int, char*); static this() { import core.stdc.wchar_; fwide(core.stdc.stdio.stdout, 1); setlocale(0, cast(char*)"china"); } ----------------------------------------------------------------------- module cnsetlocale; import std.stdio; extern(C) int setlocale(int, char*); static this() { import core.stdc.wchar_; fwide(core.stdc.stdio.stdout, 1); setlocale(0, cast(char*)"china"); } void main() { printf("a!!\n"); writefln("%s","hello,中文!!"); string msg="你好!!"; string msg1="去看电影吗?"; string msg2="是吗?"; a(msg2); writefln("the string is %s \n %s %s and %s",msg,msg1,msg2,"你要去哪儿玩?"); writeln("公园?"," 电影院?"); readln; } void a(string msg2) { writefln("the string is %s",msg2); } ------------ dmd hello //only such simple 'printf' is error,but for consumer is better,because they don't need change any things,so don't use the 'printf' function . If only test for yourself,you can add such codes for your main : import std.process; executeShell("chcp 65001"); then,change the Font to 'Lucida Console' after 'dmd hello' ( if you don't want use 65001,then open cmd,chcp 936 ,and change the Font to '宋体') ok.
Feb 12 2015