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.
Extensions to download:
C/C++ Extension Pack
C/C++ Compile Run (very important)
C/C++ Runner
Code Runner (the more the better)
2. Compiler
Let me explain here, VSCode is just an editor, if you want to run c++ files, you need to download the compiler.
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).
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
and then enter
gcc --version
g++ --version
gdb --version
(The following is an example)
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
Open environment variables
Edit the path in the system variable (if you don’t see the path below at first glance, just scroll down to find it)
new variable
Enter the path of mingw64
For example, mine is C:\msys64\mingw64\bin
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
2. Configure the default build task
Open the terminal - configure the default build task
Select g++.exe
3. Debug c++ files
Click the small triangle on the right side of the start button on the vscode page
Click on the first longest option
compileRun: compile with default... (too lazy to type)
Then congratulations,