Wired question related with Chinese characters

Adam D. Ruppe destructionator at gmail.com
Sun Mar 22 16:12:34 UTC 2020

On Sunday, 22 March 2020 at 15:19:13 UTC, walker wrote:
> writeln(var1);

writeln calls the wrong function for the Windows console.

You can kinda hack it by changing the code page like Steven said 
(which has other bugs though, but works for many cases), or you 
can call the correct function - WriteConsoleW - yourself instead.


import core.sys.windows.windows;

wstring s = ""w; // note it is a wstring, not a string
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), s.ptr, cast(DWORD) 
s.length, null, null);

my terminal.d library also calls that function but it isn't 
likely to 100% work with Chinese characters either due to other 
bugs. still you can try it if you like


import arsd.terminal;

void main()
Terminal terminal = Terminal(ConsoleOutputType.linear);
string var1 = "你好"; // I might have broken this in copy/paste
terminal.writeln(var1); // could work.

that should work if you have the fonts set up already but just it 
migh have other bugs so I kinda suggest just doing your own write 

readln in the stdlib is similarly broken btw.

More information about the Digitalmars-d-learn mailing list