1、程序路徑不能有中文,因為MinGW不支持
2、選擇一個文件夾當作工作區,並且在該文件夾下創建./vscode文件夾,並在該文件夾下創建兩個json文件
launch.json
{ "version": "0.2.0", "configurations": [ { "name": "C/C++", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, //彈出黑框使用true,不彈出使用false "MIMode": "gdb", "miDebuggerPath": "D:/MinGW/bin/gdb.exe", //選擇gbd.exe的絕對路徑 "preLaunchTask": "compile", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], }, ] }
tasks.json
{ "version": "2.0.0", "tasks": [ { "type": "shell", "label": "compile", "command": "gcc", //c文件就用gcc,cpp文件就用g++ "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true } } ] }
題外話:
如果想讓vscode運行向dev-c++一樣出現黑框的話,需要安裝C/C++ Compile Run插件
除此之外,需要將設置-擴展-Compile Run configuration中找到如下選項進行勾選,使用F6運行

