0.点击Vscode左边的debug按钮,进入debug模式,但是一开始里面没有Configuration文件。add Configuration,之后选择C++,VScode会在工作路径下自动生成一个.vscode
文件夹。
1.c_cpp_properties.json
打开vscode控制台,输入C/Cpp: Edit configurations
,就自动生成了一个c_cpp_properties.json
文件,这样你就可以在该文件中编写参数来调整设置。
{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**" ], "defines": [], "compilerPath": "/usr/bin/g++", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "clang-x64" } ], "version": 4 }
2.task.json输入Tasks: Configure Tasks
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "type": "shell", "label": "g++ build active file", "command": "/usr/bin/g++", "args": [ "-g", "${workspaceFolder}/main.cpp",//注意修改为你的文件名 "-o", "${workspaceFolder}/main"//注意修改为你定义的名字 ], "options": { "cwd": "/usr/bin" }, "problemMatcher": [ "$gcc" ], "group": "build" } ] }
3.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": "g++ - Build and debug active file", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/main",//注意修改为和task一样的名称 "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "g++ build active file", "miDebuggerPath": "/usr/bin/gdb" } ] }