Vscode C + + development environment configuration steps detailed explanation (teach you how to write c + + with vscode)


After using CB and DEVC + + for a period of time, I always felt that the highlight of CB was too poor, while DEVC + + had a poor experience (especially the code completion function). I replaced vs2017, but because it was too big, the Caton was very obvious, so I finally chose vscode, a lightweight compiler. Because I have encountered many problems in the configuration of C + + development environment, I specially wrote this blog, hoping to help the latecomers quickly realize the configuration of C + + environment.

Step 1: Download vscode

You can download it directly from the official website of vscode, and you should pay attention to choose the version that matches your own system.

Official website address: https://code.visualstudio.com/?wt.mc_ id=DX_ eight hundred and forty-one thousand four hundred and thirty-two

After entering the official website, the following interface will appear

After downloading, install by default

Open vscode

Click the fifth one in the left column, enter “Chinese” in the search box, install the first plug-in (sinicized), and then enter “C + +” to also install the first plug-in, then restart and continue with the next operation.

Step 2: download the compiler environment

Here bloggers use tdm-gcc

You can download it from Baidu official website or download it from Baidu net disk link below

Link: https://pan.baidu.com/s/1MFPVfVpeiQSLgJ009rh6Xg Extraction code: ebhv

After downloading, you can install by default, but remember the installation path of tdm-gcc, which will be used next.

Step 3: configure environment variables

After tdm-gcc is installed, we need to add its path to the system environment variables

The operation is as follows:

1. Open the control panel of the system and search for “advanced settings” in the red circle.

2. Click Advanced system settings

3. Click environment variable configuration

4. Click “path” in the system variable, and then click Edit to add the above path.

The format is in the form of c-tdm-gcc-64-bin.

Step 4: configure the environment in vscode

Open a folder in vscode, create a new folder, and select it. In this way, you can directly add it to vscode, or drag a file into vscode. Next, create a. Vscode folder under this file (note that the name must be. Vscode), which is required (generally speaking, there will be such a. Vscode configuration file in each folder). Note: if you put this folder at the top level of the common folder, you don’t need to configure it repeatedly. In the. Vscode folder, create two (only two) configuration files, namely launch.json 、 tasks.json . Just copy in the following:


 "version": "2.0.0",
 "command": "g++",
 "Args": ["- G", "${file}", "- O", "${filebasenamenoextension}. Exe"], // compile command parameters
 "problemMatcher": {
  "owner": "cpp",
  "fileLocation": ["relative", "${workspaceRoot}"],
  "pattern": {
   "regexp": "^(.*):(\d+):(\d+):\s+(warning|error):\s+(.*)$",
   "file": 1,
   "line": 2,
   "column": 3,
   "severity": 4,
   "message": 5

launch.json Be careful

 "version": "0.2.0",
 "configurations": [

   "Name": "(GDB) launch", // configuration name, which will be displayed in the drop-down menu of startup configuration
   "Type": "cppdbg", // configuration type, here can only be cppdbg
   "Request": "launch", // request configuration type, which can be launch or attach
   "Program": "${workspaceroot} / ${filebasenamenoextension}. Exe" // the path of the program to be debugged
   "Args": [] the command line parameter passed to the program during program debugging. Generally, it can be set to null
   "Stopatentry": false, // when set to true, the program will pause at the program entrance, generally set to false
   "CWD": "${workspaceroot}" // the working directory of debugging program is generally ${workspaceroot}, that is, the directory where the code is located
   "environment": [],
   "Externalconsole": true, // whether to display the console window during debugging. Generally, it is set to true to display the console
   "MIMode": "gdb",
   "Midebuggerpath": "C: \ \ tdm-gcc-64 \ \ bin \ \ gdb64. Exe" // the path of midebugger. Note that it should correspond to MinGW's path
   "Prelaunchtask": "G + +" // the task to be executed before the start of a debugging session. It is generally a compiler, C + + is G + +, C is GCC
   "setupCommands": [
     "description": "Enable pretty-printing for gdb",
     "text": "-enable-pretty-printing",
     "ignoreFailures": true

Step 5: write the first C + + program

After the configuration is complete

Build a main.cpp file

Paste the following code

#include <iostream>
using namespace std;
int main()
 cout << "Hello Vscode" << endl;
 return 0;

The interface should look like this

Because vscode will exit after executing the program, you can choose to add a breakpoint or a getchar ();

Next, run Ctrl + F5


This article about vscode C + + development environment configuration steps detailed explanation (teach you how to write c + + with vscode) is introduced here. For more related vscode C + + environment configuration content, please search previous articles of developer or continue to browse the following related articles. I hope you can support developer more in the future!

Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]