1.安裝C/C++插件
2.安裝編譯環境,這里選擇MinGW(http://mingw.org/ )
選擇一個安裝目錄,如:E:\workspace\MinGW
mingw32-gcc開頭的(包括了mingw32-gcc-g++等)、mingw32-gdb開頭的全部選擇“Mark for Installation”
下載
3.將MinGW添加到系統環境變量中(添加到Path中)
4.打開VS Code,新建一個文件夾或者打開一個文件夾如:Demo
在里面新建一個1.c文件
#include <stdio.h> int main() { printf("Welcome to 中國!!!"); return 0; }
#include<stdio.h>會出現提示的黃色小燈泡符號,點擊它,然后點擊“Add include path to settings”按鈕, 將生成並打開一c_cpp_properties.json 文件,編輯這個json文件,添加c/c++頭文件的路徑進去:(按照如下模擬配置)
c_cpp_properties.json
{ "configurations": [ { "name": "Win32", "includePath": [ "E:/workspace/MinGW/include/*", "E:/workspace/MinGW/lib/gcc/mingw32/6.3.0/include/*", "E:/workspace/MinGW/lib/gcc/mingw32/6.3.0/include/c++/*", "E:/workspace/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32/*", "E:/workspace/MinGW/lib/gcc/mingw32/6.3.0/include/c++/backward/*", "${workspaceRoot}" ], "defines": [ "_DEBUG", "UNICODE" ], "intelliSenseMode": "msvc-x64", "browse": { "path": [ "E:/workspace/MinGW/include/*", "E:/workspace/MinGW/lib/gcc/mingw32/6.3.0/include/*", "E:/workspace/MinGW/lib/gcc/mingw32/6.3.0/include/c++/*", "E:/workspace/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32/*", "E:/workspace/MinGW/lib/gcc/mingw32/6.3.0/include/c++/backward/*", "${workspaceRoot}" ], "limitSymbolsToIncludedHeaders": true, "databaseFilename": "" } } ], "version": 3 }
5.設置任務配置
在彈出的選擇欄中選擇”Others“,選擇后會創建並打開一個task.jason的配置文件, 修改如下:
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "echo", "type": "shell", "command": "gcc ", "args": ["-g", "${file}", "-o", "${workspaceRoot}/${fileBasenameNoExtension}.exe"], } ] }
6.設置調試
編輯launch.json
{ // 使用 IntelliSense 了解相關屬性。 // 懸停以查看現有屬性的描述。 // 欲了解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceRoot}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "E:/workspace/MinGW/bin/gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
7.運行 ctrl+alt+n