Windows 终端输出中文乱码问题#
这是由于部分版本下, Windows 终端默认编码为 gbk
, 而含中文文本的代码文件保存为 UTF-8
.
该问题目前没找到通用解决方案, 每种方法都存在局限性或在某些版本下出现问题. 以下是 部分 可行的方法:
法1、Windows 11 (及以后?) 更改系统区域设置#
在任务栏处 右键 后选择 区域
, 选择提示的 .
切换到 Beta 版:使用 Unicode UTF-8 提供全球语言支持
, 然后点击 .

打开设置#
法2、设置终端启动时自动切换为 UTF-8
#
点击窗口左下角的 settings.json
文件中找到 "terminal.integrated.profiles.windows"
, 并修改 "cmd"
如下:
"terminal.integrated.profiles.windows": {
"cmd": {
"args": ["/K", "chcp 65001 > nul"], // 新增加的行
"icon": "terminal-cmd",
"path": [
"${env:windir}/Sysnative/cmd.exe",
"${env:windir}/System32/cmd.exe"
]
},
"PowerShell": {
"args": ["-NoExit", "chcp 65001 > $null"], // 新增加的行
"icon": "terminal-powershell",
"source": "PowerShell"
},
},
备注
如果窗口左下角没有齿轮, 请尝试通过 Ctrl-Shift-P 或 Command⌘-Shift-P 打开命令菜单, 输入 toggle activity bar
以找到 , 回车.

打开设置#
警告
如果修改后不能执行调试任务, 说明这个方法不适合你.