重點參考:這篇
其中在調試模塊出了問題,總是提示什么進程運行時候以外退出,要安裝.Net4.6.2。
去網上下載安裝.Net4.6.2又無法安裝成功,總是說Windows Installer不能用。但是在services.msc里看,這個服務是開啟的沒問題。最后只好在騰訊電腦管家的軟件管理里面安裝它。
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "E:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
launch.json
{
// 使用 IntelliSense 了解相關屬性。
// 懸停以查看現有屬性的描述。
// 欲了解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/build/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "E:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
// 這里要與你在 tasks.json 中配置的 label 一致
"preLaunchTask": "compile",
}
]
}
launch.json右側工作區添加
{
// 在終端中運行編譯命令,否則我們無法與程序通過標准輸入交互
"code-runner.runInTerminal": true,
// 如果你全局設置中的默認終端是 WSL 之類的,那么可以在工作區設置中改回 PowerShell
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
// 運行代碼之前清除之前的輸出
"code-runner.clearPreviousOutput": true,
// 開啟這個后在運行編譯命令之前會自動 cd 至文件所在目錄
"code-runner.fileDirectoryAsCwd": true,
// 因為上面那個選項會自動 cd,所以我刪除了默認編譯命令中的 cd 語句
// 同時我將編譯結果的輸出目錄修改為了同目錄下的 build 文件夾
// 不然源碼文件和編譯結果混雜在一個目錄中非常雜亂(尤其是刷題時)
// 這里只保留了 C 和 C++ 的編譯命令,有需要其他語言的請自行添加
"code-runner.executorMap": {
"c": "gcc $fileName -o build/$fileNameWithoutExt && .\\build\\$fileNameWithoutExt",
"cpp": "g++ $fileName -o build/$fileNameWithoutExt && .\\build\\$fileNameWithoutExt",
},
// 運行代碼后切換焦點至終端,方便直接輸入測試數據
"code-runner.preserveFocus": false,
// 在運行代碼之前保存文件
"code-runner.saveFileBeforeRun": 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": "compile",
"type": "shell",
"command": "g++",
"args": [
"-g",
"\"${file}\"",
"-o",
"\"${fileDirname}\\build\\${fileBasenameNoExtension}\""
],
"presentation": {
"reveal": "always",
"panel": "shared",
"focus": false,
"echo": true
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": "absolute",
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
