0 environment

  • System: win10
  • Editor: vscode

1 Related Installation

Vscode download

MinGW download

To get the latest version of MinGW, scroll down to the latest version of “x86_64-POSIX-seh” and click download. If you don’t need MinGW, just download the one I provided above

Vscode C plug-in download
Figure Path needs to be created for the first installation

Press win + R, enter CMD, enter g++ -v/ GCC -v, and press enter. If GCC version is displayed, the environment variable is configured successfully. Otherwise, reconfigure the environment variable.

2 vscode configuration

1 Installation directory and Demo download

C directory

Vscode C environment to build demo Git download address

Vscode C environment to build demo Git download address

2 Environment Configuration (Recommended)

Because there are a lot of online tutorials only write focus can refer to other people’s article 1. New 1. CPP file

#include <stdio.h>
#include <windows.h>

int main(a)
{
 printf("Hello World\n");  system("pause");  return 0; } Copy the code

2. Go to the debugging interface and add the configuration environment. Select C++(GDB/LLDB) and g++

{
    "version": "0.2.0".    "configurations": [ 
     {
      "name": "g++.exe build and debug active file". "type": "cppdbg". "request": "launch". "program": "${fileDirname}\\${fileBasenameNoExtension}.exe". "args": []. "stopAtEntry": false. "cwd": "${workspaceFolder}". "environment": []. "externalConsole": true// Change this item to pop up the terminal "MIMode": "gdb". "miDebuggerPath": "D:\\install\\mingw\\bin\\gdb.exe"// The real location of the mingw GDB on your computer "setupCommands": [  {  "description": "Enable pretty-printing for gdb". "text": "-enable-pretty-printing". "ignoreFailures": true  } ]. "preLaunchTask": "C/C++: gcc.exe build active file"  }  ]  }  Copy the code

4. Return to the. CPP file and press F5 to debug the tasks.json file is automatically generated

{
 "version": "2.0.0". "tasks": [
  {
   "type": "shell". "label": "C/C++: gcc.exe build active file". "command": "D:\\install\\mingw\\bin\\g++.exe"// The real path of mingw needs to be modified accordingly "args": [  "-g". "${file}". "-o". "${fileDirname}\\${fileBasenameNoExtension}.exe" ]. "options": {  "cwd": "D:\\install\\mingw\\bin"// The real path of mingw needs to be modified accordingly },  "problemMatcher": [  "$gcc" ]. "group": "build"  }  ]  } Copy the code

5. The value of “preLaunchTask” in the launch.json file must be consistent with the value of “label” in the tasks.json file. The value setting depends on personal preference, and it is OK to keep the default.

3 other ways to run (vscode plug-in)

It is better to install Code Runner or Compile Run in C/C++

  • Install Code Runner
  • Install C/C++ Compile Run