table of Contents
1. Download and configure MinGW
1. Download and unzip MinGW
Download link : https://sourceforge.net/projects/mingw-w64/files/
Scroll down after opening the link, we download the latest 8.1.0
, you can see that there are various versions, here is recommended to downloadx86_64-posix-seh
Version description :
X86_X64
: 64th
win32
: Developing Windows programsposix
:Develop programs under Linux, Unix, Mac OS and other operating systems64-bit has two exception handling models to choose from, which
seh
are newly invented andsjlj
ancient. seh performance is better, but 32-bit is not supported. sjlj has good stability and supports 32-bit
i686
: 32nd
win32
: Developing Windows programsposix
:Develop programs under Linux, Unix, Mac OS and other operating systems32-bit
dwarf
andsjlj
two kinds of exception handling model for selection. The performance of dwarf is better than sjlj, but it does not support 64-bit
Click the selected version to download, after downloading, you will get the 7z
compressed file, decompress it to getmingw64
2. Configure environment variables
Click mingw64 to enter and you can see the bin
directory, then add bin
the path of the directory to the environment variable
- Press the
Win + R
key to open the operating window, entersysdm.cpl
a carriage return; - In the pop-up
系统属性
window, select the高级
tab; - In the
高级
find tab环境变量
button, click the环境变量
button to open the环境变量
window; - In the
环境变量
window,系统变量
find the area ofPath
variable, double-clickPath
appears编辑环境变量
the window; - In the
编辑环境变量
window, click新建
, enter the path to the bin directory in the new line, and then click OK.
3. Test whether the configuration is successful
Press the Win + R
button to open the Run window, enter cmd
a carriage return, enter the command linegcc -version
C:\Users\zsr204>gcc --version
gcc (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If the above result appears, it means the installation and configuration are successful
Two, install the C/C++ plug-in
In VS Code in the Ctrl + shift + x
open store, search c/c++
, select first be installed
Three, the first program
Create an empty directory, open with VS Code, and then create a .cpp
file, write a simple code
after completion, you can see the button is not running; this time we click on the sidebar 运行
, click 启动调试
and then select GDB/LLDB
and choose g++.exe
this time being given
attention ! ! This is not a configuration problem, but the .cpp
file path cannot contain Chinese. We create a new .cpp
file in another English directory and repeat the above code
Follow the above steps again, click to start debugging, select GDB/LLDB
, and then select g++.exe
. At this time, the following interface will automatically pop up. At this time, we switch to hello.cpp
and click the run button in the upper left corner to run the
result:
ps: .cpp
At the end of the run , a .exe
file will also be generated . .cpp
When there are a lot of exe
files, a lot of files will be generated , which seem to interfere with the line of sight, we can set the hidden
Click the lower left corner to open the settings,
swipe down, find Files:Exclude
, select the add mode, enter **/*.exe
, and click OK.
Then you can't see the exe
file, it has been hidden
Fourth, related plug-in recommendation
1. Visual Studio IntelliCode
Visual Studio IntelliCode
(IntelliCode) is a set of AI auxiliary functions that can improve the work efficiency of developers through functions such as contextual intelligence, parameter completion, code format and style rule inference.
IntelliCode extends existing developer workflows with machine learning services that can help you understand the code and its context. It is now available for C#, C++ (preview), JavaScript/TypeScript (preview) and XAML code, and will be updated in the future to support more languages.
Official website: https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.VSIntelliCode
2. Code Runner
Run code segments or code files in multiple languages to achieve one-click compilation and operation
Official website: https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
After installation, perform the relevant configuration, Ctrl+Shift+p
open the command panel and input. 打开设置
Select the first one to open the settings.json
file, then add the code shown in the figure below and save
it We can .cpp
click the run button in the upper right corner of the file to run with one key,
or right-click run code
to run directly