1、下載VScode!
2、安裝MinGW(里面包含gcc和g++的編譯器)
3、配置環境變量
4、VScode安裝插件
5、VScode如何開啟debug模式
喜歡debug的朋友可能發現這種模式下、只能直接運行代碼、並不能單點debug什么的、下面介紹如何開啟debug模式。
新建一個普通的項目、如下圖所示,此時按下F5、項目旁邊就會出現一個.vscode文件夾
注意:涉及路徑的地方(miDebuggerPath、command、cwd)記得填自己的路徑
1、launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", // 配置名稱,將會在啟動配置的下拉菜單中顯示
"type": "cppdbg", // 配置類型,這里只能為cppdbg
"request": "launch", // 請求配置類型,可以為launch(啟動)或attach(附加)
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", // 將要進行調試的程序的路徑
"args": [], // 程序調試時傳遞給程序的命令行參數,一般設為空即可
"stopAtEntry": false, // 設為true時程序將暫停在程序入口處,一般設置為false
"cwd": "${workspaceFolder}", // 調試程序時的工作目錄,一般為${workspaceFolder}即代碼所在目錄
"environment": [],
"externalConsole": true, // 調試時是否顯示控制台窗口,一般設置為true顯示控制台
"MIMode": "gdb",
"miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe", // miDebugger的路徑,注意這里要與MinGw的路徑對應
"preLaunchTask": "g++", // 調試會話開始前執行的任務,一般為編譯程序,c++為g++, c為gcc
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
2、tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++",
"command": "D:\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
]
}
]
}
3、測試
5、BUG調試
若出現檢測到 #include 錯誤。請更新 includePath這一類的錯誤、按以下內容操作。
1、輸入命令
g++ -v -E -x c++ -
輸入此命令、復制以下路徑。
隨后在VScode編譯器中按下 Ctrl + Shift + P鍵、按下回車
右邊會出現c_cpp_properties.json文件、修改這個文件如下圖所示