以下三个文件放在 项目下 .vscode
文件夹中,内容从网络收集,经自己实践添加修改以备忘
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
// tasks.json这个文件是定义调试开始前要执行的任务,即(或者绝大多数是)编译程序,
// 定义了用于编译程序的编译器,所输出的文件格式,使用的语言标准等
// 下载mingw-w64 https://www.mingw-w64.org/downloads/
"version": "2.0.0",
"tasks": [
{
"label": "g++编译",
"command": "C:/mingw/bin/g++.exe", // 根据自己的路径修改,记得添加bin路径到path环境变量
"args": [
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-g",
"-static-libgcc",
"-fdiagnostics-color=always",
"-std=c++14" // 如果c++17报错,可能编译器不支持,尝试降低版本
],
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "shared"
},
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
},
]
}
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", // 配置类型,这里只能为cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "${fileDirname}", // 调试程序时的工作目录,一般为${fileDirname}即代码所在目录
"environment": [],
"externalConsole": false, // 调试时是否显示控制台窗口
"MIMode": "gdb",
"miDebuggerPath": "C:/mingw/bin/gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应
"preLaunchTask": "g++编译", // 跟 tasks.json 的 label 字段一致
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/mingw/include/*" // 根据自己的需要添加多个
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/mingw/bin/gcc.exe", // 修改为自己的路径
"cStandard": "c11",
"cppStandard": "c++14", // 如果c++17报错,可能编译器不支持,尝试降低版本
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}