Re: How to write asia characters on console?

2015-02-12 Thread FrankLike via Digitalmars-d-learn

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\ddmd hello.d -offilename hello.exe
C:\D\dmd2\samples\dhello.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.



Re: How to write asia characters on console?

2015-02-11 Thread Kagamin via Digitalmars-d-learn

https://issues.dlang.org/show_bug.cgi?id=2742


Re: How to write asia characters on console?

2015-02-11 Thread Andre Artus via Digitalmars-d-learn

On Sunday, 8 February 2015 at 05:56:22 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\ddmd hello.d -offilename hello.exe
C:\D\dmd2\samples\dhello.exe
hello浣犲ソ

thanks.


I just tried this on my Mac(utf8) and it worked as expected. I 
see that you are using Windows, I'm not near a Win* machine right 
now, but can check later.


Re: How to write asia characters on console?

2015-02-08 Thread Lave Zhang via Digitalmars-d-learn

On Sunday, 8 February 2015 at 06:26:38 UTC, Ali Çehreli wrote:

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\ddmd hello.d -offilename hello.exe
C:\D\dmd2\samples\dhello.exe
hello浣犲ソ

thanks.


This thread may be useful:


http://forum.dlang.org/thread/suzymdzjeifnfirtb...@dfeed.kimsufi.thecybershadow.net#post-suzymdzjeifnfirtbnrc:40dfeed.kimsufi.thecybershadow.net

Ali


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;
}


Re: How to write asia characters on console?

2015-02-08 Thread mzfhhhh via Digitalmars-d-learn


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/jfawjvoedsxsznsue...@forum.dlang.org#post-tyslcbycorgfaqimldnd:40forum.dlang.org


Re: How to write asia characters on console?

2015-02-07 Thread Ali Çehreli via Digitalmars-d-learn

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\ddmd hello.d -offilename hello.exe
C:\D\dmd2\samples\dhello.exe
hello浣犲ソ

thanks.


This thread may be useful:


http://forum.dlang.org/thread/suzymdzjeifnfirtb...@dfeed.kimsufi.thecybershadow.net#post-suzymdzjeifnfirtbnrc:40dfeed.kimsufi.thecybershadow.net

Ali



Re: How to write asia characters on console?

2015-02-07 Thread weaselcat via Digitalmars-d-learn

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\ddmd hello.d -offilename hello.exe
C:\D\dmd2\samples\dhello.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.


How to write asia characters on console?

2015-02-07 Thread Lave Zhang via Digitalmars-d-learn

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\ddmd hello.d -offilename hello.exe
C:\D\dmd2\samples\dhello.exe
hello浣犲ソ

thanks.


How to write asia characters on console?

2015-02-07 Thread Lave Zhang via Digitalmars-d-learn

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\ddmd hello.d -offilename hello.exe
C:\D\dmd2\samples\dhello.exe
hello浣犲ソ

thanks.