1、下載安裝VSCode,安裝mscpptools ,直接搜索c++,或者mscpptools


2、下載MinGW
安裝好,一般默認安裝到C:\MinGW
安裝好后直接啟動。
選擇需要的gcc ,g++
如圖:1、選擇mingw32-gcc,mingw32-gcc-g++,
2、右鍵,mark For Installtion...
3、點擊菜單欄第一個 Installation,選擇apply changes,然它自動在線安裝。

3、安裝成功之后,配置環境變量,不多說了

4、重啟vsCode,新建->新建一個文件夾,在該文件夾下新建一個 test.cpp,寫一些代碼:
1 #include <iostream> 2 using namespace std; 3 4 void shellInsertSort(int a[], int n, int dp){ 5 6 } 7 int main(int argc, char *args[]){ 8 cout <<"hello world!"<<endl; 9 getchar(); 10 return 0; 11 }
5、新建一個launch.json
填寫配置:
1 { 2 "version": "0.2.0", 3 "configurations": [{ 4 "name": "C++ Launch (GDB)", // 配置名稱,將會在啟動配置的下拉菜單中顯示 5 "type": "cppdbg", // 配置類型,這里只能為cppdbg 6 "request": "launch", // 請求配置類型,可以為launch(啟動)或attach(附加) 7 "launchOptionType": "Local", // 調試器啟動類型,這里只能為Local 8 "targetArchitecture": "x86", // 生成目標架構,一般為x86或x64,可以為x86, arm, arm64, mips, x64, amd64, x86_64 9 "program": "${file}.exe", // 將要進行調試的程序的路徑 10 "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", // miDebugger的路徑,注意這里要與MinGw的路徑對應 11 "args": [], // 程序調試時傳遞給程序的命令行參數,一般設為空即可 12 "stopAtEntry": false, // 設為true時程序將暫停在程序入口處,一般設置為false 13 "cwd": "${workspaceRoot}", // 調試程序時的工作目錄,一般為${workspaceRoot}即代碼所在目錄 14 "externalConsole": true, // 調試時是否顯示控制台窗口,一般設置為true顯示控制台 15 "preLaunchTask": "g++" // 調試會話開始前執行的任務,一般為編譯程序,c++為g++, c為gcc 16 }] 17 }
6、新建一個task.json,配置如下:
1 { 2 "version": "0.1.0", 3 "command": "g++", 4 "args": ["-g", "${file}", "-o", "${file}.exe"], // 編譯命令參數 5 "problemMatcher": { 6 "owner": "cpp", 7 "fileLocation": ["relative", "${workspaceRoot}"], 8 "pattern": { 9 "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", 10 "file": 1, 11 "line": 2, 12 "column": 3, 13 "severity": 4, 14 "message": 5 15 } 16 } 17 }
7、按F5調試

