Printing wide characters in console

Jun blings at naver.com
Fri Jan 7 04:37:08 PST 2011


I think I found a solution for it. This code changes encoding of string to
ansi which is default string encoding in windows console.

import std.c.windows.windows;

string ansi(string str)
{
	wchar[] src = toUTF16(str).dup;
	char[] dest;
	dest.length = str.length;
	WideCharToMultiByte(0, 0, src.ptr, -1, dest.ptr, dest.length, null,
null);
	return cast(string)dest;
}

It's inconvinient to call this function every time printing string, I think
simillar code should be in the standard library.



More information about the Digitalmars-d-learn mailing list