看过我的另外一篇文章就懂了这一篇是什么了?
第一步,我的工程文件所需要建立一下几个文件
四个json文件,setting有没有都没有影响。主要的是task.json和launch.json
(1)先建立一个main.cpp文件,键入一下程序测试
#include<iostream>
using namespace std;
int main()
{
cout<<"hello c++"<<endl;
system("pause");
}
(2)然后点击小虫子
(3)选择Windows的选项创建launch.json文档和task.json文档
然后就是以一下代码覆盖即可
launch.json文件
注意下这句,这句的路径是自己下载MinGW的gdb.exe位置
“miDebuggerPath”: “C:/Users/sms/Documents/MinGW/bin/gdb.exe”,
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/Users/sms/Documents/MinGW/bin/gdb.exe",
"preLaunchTask": "g++",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
]
}
(4)task.json文件
{
"version": "2.0.0",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileBasenameNoExtension}.exe"
], // 编译命令参数
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
(5)最后是c_cpp_properties.json(通过Ctrl+Shift+P创建):
同样这句,也是同样的路径,
“compilerPath”: “C:\Users\sms\Documents\MinGW\bin\gdb.exe”,
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\Users\\sms\\Documents\\MinGW\\bin\\gdb.exe",
"cStandard": "gnu11",
"cppStandard": "gnu++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
即可