[VSCode] C++ environment configuration (a must-see for beginners)

About VSCode's c++ environment configuration

There are many online tutorials, but most of them are difficult for beginners to understand and cannot operate. The author himself has been fiddling for a long time before configuring the c++ operating environment.

This article will briefly describe the process of vscode configuring the c++ environment from beginning to end. Although it is a brief introduction, after reading this article, at least I think it must have benefited a lot from configuring the c++ environment for Xiaobai.

(The main focus is an easy one) If there are deficiencies in the content, please point it out.


1. Basic configuration of VSCode

I believe that those who want to configure c++ for vscode should have downloaded vscode. Here, you can first create a folder for c++ files and add it to vscode.

3bab6ed6db77f2aa92cc1a86f6dd97d4.png

Extensions to download:

C/C++ Extension Pack

e28e35444504d04209795019c01b30b4.png

C/C++ Compile Run (very important)

0d5b734b6c23e56996558c2fde9c12ed.png

C/C++ Runner

c50696b6b5f0cf33d7c404b06247d6a6.png

Code Runner (the more the better)

ff3c2029eff40edc79d2bb7dbf4cf1a3.png

2. Compiler

Let me explain here, VSCode is just an editor, if you want to run c++ files, you need to download the compiler.

1eb000f5d7e8631e7fcd2dfdbd6532c1.png

In a word, just download msys2 ( it is better to install it on the c drive, which is more convenient ). There are specific download tutorials on the Internet.

gcc and gdb download

After downloading msys2, it still doesn’t work. You need to use MSYS2 MinGW 64 to download gcc and gdb (you need to send instructions in it, it’s not difficult, just follow the online tutorial).

5f11577358b58681ea555eb2200eb59f.png

This online search also has detailed tutorials. I personally recommend downloading all at once when downloading . If there is anything unnecessary, just go back and delete it .

test installation

If you want to know whether the installation was successful, you can run the command line as an administrator

Enter the cd installation path   

//Switch to the installation directory first

821dff01138e0f3c8ee786884e8048cf.png

and then enter

gcc --version

g++ --version

gdb --version

(The following is an example)

e247da9f40465a5e9162d68039767b98.png
2526fafe8b2948ba93bd22408d4c874c.png

There will be output if the installation is successful.

Environment variable configuration

Here is the direct shortcut key win+pause (search how to open the environment variable if you don’t understand this part)

Open advanced system settings

32fcf4d1c6fc51b033010378f435e74a.png

Open environment variables

34c57ed452602aed435ad10e84f7cfc7.png

Edit the path in the system variable (if you don’t see the path below at first glance, just scroll down to find it)

ab5751df1713d238662be6680b06f866.png
490ed1bfd111fa7ee8eeb1e78bae8362.png

new variable

34f8ad783f2e573df9096a49109c2bd2.png
1ecc4bb7d0d29dfddf6dfb3336710419.png

Enter the path of mingw64

For example, mine is C:\msys64\mingw64\bin

ae9f31d264f058c922df432c29fde63f.png

Remember to save after typing ! !

3. Run the c++ file in VSCode

1. Create a new c++ source file (.cpp)

Enter a string of source code

#include <iostream>

using namespace std;

int main(){

cout<<"hello";

}

Save after input

f833c12fdae9150e1ac610138c3eb579.png

2. Configure the default build task

Open the terminal - configure the default build task

327866e281a8dca69bba6e44cb6713be.png

Select g++.exe

7c2c3dccb814b611f8be1ba98adf097f.png

3. Debug c++ files

Click the small triangle on the right side of the start button on the vscode page

143c9e168610cad20b3a5803759f3fd3.png

Click on the first longest option

compileRun: compile with default... (too lazy to type)

a2220cbcc005fd349bddbcb1070ae174.png

Then congratulations,

The c++ operating environment configuration is successful!

Guess you like

Origin blog.csdn.net/xiaowang_lj/article/details/131891429