视频介绍
【初学者必看】VSCode配置调试C/C++代码(2022最新版)
修改配置文件
- launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径
"MIMode": "gdb",
"miDebuggerPath": "D:\\Microsoft VS Code\\mingw64\\bin\\gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应
"preLaunchTask": "gcc", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
- tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "gcc",
"command": "D:/Microsoft VS Code/mingw64/bin/gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
""
],
"options": {
"cwd": "D:/Microsoft VS Code/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "编译器: \"D:/Microsoft VS Code/mingw64/bin/gcc.exe\""
}
]
}
解决中文乱码
task.json
"-fexec-charset=GBK"