##VScode拓展包
##新建cpp文件
##配置编译文件tasks.json
快捷键“⇧⌘B”
###配置内容如下
其中注意label,与之后的自动调试执行launch.json
的preLaunchTask
有关
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "g++",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileBasenameNoExtension}.out"
],
"problemMatcher": { //正则匹配,删除无用符号
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
##Debug配置
###添加“launch.json”文件配置
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out", // 将要进行调试的程序的路径
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录
"environment": [],
"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
"MIMode": "lldb",
"preLaunchTask": "g++", // 调试会话开始前执行的任务,这里为认为名字
"setupCommands": [
{
"description": "Enable pretty -printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
##编译运行
快捷键“F5”。注意,“F5”只是调试快捷键,但是我们在Launch.json里配置了,调试会话开始前执行g++的tasks.json的任务自动编译了,手动编译快捷键“⇧⌘B”。