略有更改,以支持多個cpp在同一個文件夾中的情況。
主要是tasks.json的args設置,launch.json的program路徑設置。
launch.json內容,執行程序用
{ // 使用 IntelliSense 了解相關屬性。 // 懸停以查看現有屬性的描述。 // 欲了解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) 啟動", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}.out", //要生成的可執行程序 "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, //允許打開終端 "MIMode": "gdb", "preLaunchTask": "build", //在啟動之前,先執行tasks.json(編譯、鏈接) "setupCommands": [ { "description": "為 gdb 啟用整齊打印", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
tasks.json內容,編譯、鏈接用
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", //與launch.json中"preLaunchTask": "build",一致 "type": "shell", "command": "g++", "args": [ "-g", "${fileDirname}/**cpp", //單個、多個cpp文件都可以 "-o", "${fileDirname}/${fileBasenameNoExtension}.out", //與launch.json的"program"對應 "-std=c++17" //c++版本 ], "group": { "kind": "build", "isDefault": true } } ], "presentation": { "echo": true, "reveal": "always", "focus": false, //"panel": "shared", //"showReuseMessage": true, //"clear": false } }
