是CodeBlocks编译器设置问题,在CodeBlocks菜单
settings -> compiler and debugger settings -> global compiler settings -> compiler settings -> Other Options,
在其中输入语句
-fexec-charset=GBK -finput-charset=UTF-8
实际上就是参数设置,前一个参数表示文件运行时的编码为GBK(可以正确显示中文),后一个参数表示输入文件编码格式为UTF-8.

code blocks无法输出中文解决方法_参数设置