1.安裝VS Codehtml
2.安裝插件ios
在左側插件庫c++
必須:json
c/c++ 插件windows
非必需:架構
C++ Intellisense測試
Include Autocompletespa
3.安裝編譯調試環境mingw插件
MinGW是是將GCC編譯器和GNU Binutils移植到Win32平臺下的產物,包括一系列頭文件(Win32API)、庫和可執行文件。MinGW是從Cygwin(1.3.3版)基礎上發展而來。GCC支持的語言大多在MinGW也受支持,其中涵蓋C、C++、Objective-C、Fortran及Ada。命令行
建議離線安裝MinGW 可參考
配置好環境變量
經過g++ xx.cpp -o xx 檢測是否能夠用命令行來編譯c++文件,能夠運行則安裝成功
4.調試環境配置
新建文件夾Test
新建.vscode文件夾
在.vscode下建立配置文件c_cpp_properties.json、launch.json、tasks.json
(1)c_cpp_properties.json
配置文件指定mingw所在位置,方便vscode自動調用
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceRoot}", "D:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "D:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "D:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "D:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include", "D:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1", "D:/mingw64/x86_64-w64-mingw32/include/" ], "defines": [ "_DEBUG", "UNICODE", "__GNUC__=6", "__cdecl=__attribute__((__cdecl__))" ], "intelliSenseMode": "clang-x64", "browse": { "path": [ "${workspaceRoot}", "D:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "D:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "D:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "D:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include", "D:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1", "D:/mingw64/x86_64-w64-mingw32/include/" ] }, "compilerPath": "D:\\mingw64\\bin\\gcc.exe", "cStandard": "c11", "cppStandard": "c++17" } ], "version": 4 }
(2)launch.json文件
{ "version": "0.2.0", "configurations": [ { "name": "C++ Launch (GDB)", // 配置名稱,將會在啓動配置的下拉菜單中顯示 "type": "cppdbg", // 配置類型,這裏只能爲cppdbg "request": "launch", // 請求配置類型,能夠爲launch(啓動)或attach(附加) "targetArchitecture": "x86", // 生成目標架構,通常爲x86或x64,能夠爲x86, arm, arm64, mips, x64, amd64, x86_64 "program": "${file}.exe", // 將要進行調試的程序的路徑 "miDebuggerPath": "d:\\mingw64\\bin\\gdb.exe", // miDebugger的路徑,注意這裏要與MinGw的路徑對應 "args": [ "blackkitty", "1221", "# #" ], // 程序調試時傳遞給程序的命令行參數,通常設爲空便可 "stopAtEntry": false, // 設爲true時程序將暫停在程序入口處,通常設置爲false "cwd": "${workspaceRoot}", // 調試程序時的工做目錄,通常爲${workspaceRoot}即代碼所在目錄 "externalConsole": true, // 調試時是否顯示控制檯窗口,通常設置爲true顯示控制檯 "preLaunchTask": "g++" // 調試會話開始前執行的任務,通常爲編譯程序,c++爲g++, c爲gcc } ] }
(3)tasks.json
{ "version": "0.1.0", "command": "g++", "args": [ "-g", "${file}", "-o", "${file}.exe" ], // 編譯命令參數 "problemMatcher": { "owner": "cpp", "fileLocation": [ "relative", "${workspaceRoot}" ], "pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 } } }
(4)在Test下新建測試文件test1.cpp
#include <iostream> #include <windows.h> using namespace std; int main() { std::cout << "hello, I love you!" << std::endl; system("pause"); return 0; }
運行調試
左側的debug
輸出結果