D语言新手问题 控制台中文乱码解决

· Created · Last modified by Ding replied at · 1670 times read

解决方案是搬过来的

import std.stdio;

void main()
{
	version( Windows ) {
		//直接运行中文显示乱码,原因在于Windows控制台默认编码为 936,而D语言输出utf-8
		//可以将控制台编码修改为 utf-8,命令为 "CHCP 65001"
		//修改后就可以显示中文了
		import core.sys.windows.windows;
		SetConsoleCP(65001);
		SetConsoleOutputCP( 65001 );
	}

    writeln("Hello World! 你好,中国!");
}

更多:https://superuser.com/questions/269818/change-default-code-page-of-windows-console-to-utf-8

Login to reply