乱码原因:
代码是用utf8编码格式写的,Cmake调用的Windows Powershell终端是GBK编码格式。
解决方法:
将在VSCode中打开的终端改为utf8格式
Ctrl + Shift + P 输入 setting 找到 打开用户设置(JSON),.json文件中加入如下代码,使得在VSCode中打开的PowerShell和cmd终端都为utf8(即65001)。
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": ["-NoExit","chcp 65001"]
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": ["/K","chcp 65001"],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash"
}
}
哪怕Cmake输出为GBK编码格式,但代码是utf8格式的,我们以utf8格式的终端运行utf8格式的代码是没问题的。