VScode创建C++项目
假设系统已经安装了MinGW64
插件
创建Project
配置json文件
需要修改的地方都在下方注释说明,根据MinGW64安装位置进行修改
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\MinGW64\\mingw32\\bin\\g++.exe",//根据实际情况自行修改
"cStandard": "c11",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"args": [],
"program": "${fileDirname}\\..\\output\\${fileBasenameNoExtension}.exe",//{fileDirname}:文件所在的文件夹路径,..表示父路径,表示编译文件的路径
"stopAtEntry": false,//调试时在main方法处停住
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"program": "${workspaceFolder}/output/main"
},
"osx": {
"MIMode": "lldb",
"miDebuggerPath": "lldb-mi",
"program": "${workspaceFolder}/output/main"
},
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "D:\\MinGW64\\mingw32\\bin\\gdb.exe",//根据安装位置自行修改
"setupCommands": [ {
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}]
},
"preLaunchTask": "g++"//编译C++为g++,编译C为gcc
}
]
}
settings.json
{
"code-runner.runInTerminal": true,
"files.autoSave": "onFocusChange",
"editor.lineHeight": 26,
"editor.fontSize": 14,
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "g++", //任务的名称
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"cwd": "${fileDirname}"//源文件的路径
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new", //这里shared表示共享,改成new之后每个进程创建新的端口
"showReuseMessage": true,
"clear": false
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"windows": {
"command": "D:\\MinGW64\\mingw32\\bin\\g++.exe",//根据安装位置自行修改
"args": [
"-Wall",
"-std=c++17",
"${file}",
"-g",
"-o",
"${fileDirname}/../output/${fileBasenameNoExtension}.exe" //程序运行的路径
]
},
"linux": {
"command": "bash",
"args": [
"-c",
"make"
]
},
"osx": {
"command": "bash",
"args": [
"-c",
"make"
]
}
}
]
}
编译运行
设置断点按F5运行即可