解决VsCode 调试C语言乱码问题的一种方法
当我们在配置好了C的环境后,在调试时有可能出现乱码问题;
查阅了网上相关资料,并附上我的配置文件
这是launch.json文件
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
//"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build" //修改此项
}
]
}
这是tasks.json文件
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"windows": {
"command": "g++",
"args": [
"-ggdb",
"\"${file}\"",
"--std=c++11",
"-o",
"\"${fileDirname}\\${fileBasenameNoExtension}.exe\"",
"-finput-charset=UTF-8",//输入编译器文本编码 默认为UTF-8
"-fexec-charset=UTF-8"//编译器输出文本编码 自行选择
]
}
}
]
}
在设置好了这两个文件后
编写C语言小程序,在运行时选择GBK编码保存,调试的时候选择UTF-8保存,即可解决显示乱码问题
图一
图二
图三