www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - CJK problem when using console outputs

reply zhani <dummy dummy.org> writes:
howdy :-)

i got some problem about using CJK in windows10 console.

here my code(a code file encoded the utf-8):
--------------------------------------------------
import std.stdio;
/*
static this(){
	core.stdc.wchar_.fwide(core.stdc.stdio.stdout, 1);
	setlocale(0, cast(char*)"korea");
}*/
void main()
{
	writeln("Allo");
	writeln("こんにちは"); // C
	writeln("你好");      // J
	writeln("안녕하세요"); // K
}
--------------------------------------------------

and nice result on windows(cmd and powershell):
--------------------------------------------------
Allo
?볝굯?ャ걾?
鵝졾?
?덈뀞?섏꽭?
--------------------------------------------------
wow, very cool. see, wolrd-wise came here on dmd.


In fact, when i using dmd that older version, i solved this 
problem with a cheated a way like this:
--------------------------------------------------
static this(){
	core.stdc.wchar_.fwide(core.stdc.stdio.stdout, 1);
	setlocale(0, cast(char*)"korea");
}
--------------------------------------------------

but the 'dmd v2.081.1' didnt want this.
i guess, because a core package is invisiable now. yap.

how can i solve this problem using clean a way?
thanks.
Jul 16 2018
next sibling parent zhani <dummy dummy.org> writes:
On Monday, 16 July 2018 at 09:30:22 UTC, zhani wrote:
 howdy :-)

 i got some problem about using CJK in windows10 console.

 [...]
oh, sorry for my mistake. here: --------------------------------------------------
 	writeln("你好");      // C
 	writeln("こんにちは"); // J
 	writeln("안녕하세요"); // K
--------------------------------------------------
Jul 16 2018
prev sibling parent reply ag0aep6g <anonymous example.com> writes:
On 07/16/2018 11:30 AM, zhani wrote:
 i got some problem about using CJK in windows10 console.
 
 here my code(a code file encoded the utf-8):
 --------------------------------------------------
 import std.stdio;
 /*
 static this(){
      core.stdc.wchar_.fwide(core.stdc.stdio.stdout, 1);
      setlocale(0, cast(char*)"korea");
 }*/
 void main()
 {
      writeln("Allo");
      writeln("こんにちは"); // C
      writeln("你好");      // J
      writeln("안녕하세요"); // K
 }
 --------------------------------------------------
 
 and nice result on windows(cmd and powershell):
 --------------------------------------------------
 Allo
 ?볝굯?ャ걾?
 鵝졾?
 ?덈뀞?섏꽭?
 --------------------------------------------------
Try this: ---- import std.stdio: writeln; import std.exception: enforce; import core.sys.windows.windows: CP_UTF8, SetConsoleOutputCP; void main() { SetConsoleOutputCP(CP_UTF8).enforce; writeln("Allo"); writeln("こんにちは"); writeln("你好"); writeln("안녕하세요"); } ----
Jul 16 2018
parent zhani <dummy dummy.org> writes:
On Monday, 16 July 2018 at 18:16:45 UTC, ag0aep6g wrote:
 On 07/16/2018 11:30 AM, zhani wrote:
 [...]
Try this: ---- import std.stdio: writeln; import std.exception: enforce; import core.sys.windows.windows: CP_UTF8, SetConsoleOutputCP; void main() { SetConsoleOutputCP(CP_UTF8).enforce; writeln("Allo"); writeln("こんにちは"); writeln("你好"); writeln("안녕하세요"); } ----
thank you for reply. :-) i removed a code that my cheated and solved it. i still, don't know why dmd didn't support CJK by default when write a console. Dlang must be a world-wise for everyone. anyway, thank you so much.
Jul 17 2018