To form good habits, point a praise walk
Have questions, please private letters, comments, and I will see to reply
- Download VSCode of
the country, if not through special methods VSCode official website download speed is very slow;
you can also use my offer blue cloud playing links: VSCodeUserSetup-x64-1.43.0.exe download;
if you can not meet the above requirements on the network to download the articles on VSCode dazzling selection of their own right; - A directory, the directory two: Install the plug-ins and compiler
- C code written in C VSCode the need to establish a work area
- C ++ code written in C ++ VSCode the need to create a workspace
- Contents Five: explain the C / C ++ Debug operation of
Article Directory
My programming of the road like most people, is to start by the university in the first programming course "C language"
At that time, the teacher recommended that two lightweight C compiler: Dev C ++, Visual C ++ 6.0, both the C language editor is really easy to use, but
- VC 6.0 is 1998 old products, a variety of compatibility issues in today's popular operating system, I started to abandon it
- Dev C ++ for the novice to learn C language is a good tool, but it started after by C language, because it provides the functionality is really limited, I can not meet the growing demand, I like a man, like going to slag her abandoned
- Later, the network learned that there is a very powerful C language standard IDE: Visual Studio, but this version too much stuff, a huge body mass, a C language learners just started using Visual Studio like artillery to fight mosquitoes, is not necessary; also like a small fart Wazi the masters, powerless; Visual Studio really made it was just started programming my eyes, dizziness, then eventually returned to the arms of Dev C ++
Until today, Microsoft's VSCode increasingly popular, after trying to download and found the experience very good;
VSCode Although only built in JavaScript, TypeScript and Node.js, but it has a very rich language of the other plug-in extension system
It comes with built-in support for JavaScript, TypeScript and Node.js and has a rich ecosystem of extensions for other languages (such as C++, C#, Java, Python, PHP, Go) and runtimes (such as .NET and Unity).
Then plan to use VSCode configure the C / C ++ environment, I occasionally meet the needs of the C programming language, but also the record of this process, we hope to help
A directory: Microsoft C / C ++ extension
- Open VSCode
- Click on the sidebar Manage extensions icon
- Search C / C ++ , click install to
In the C / C ++ for Visual Studio Code (Preview) , clearly illustrate this plug-in does not include the C ++ compiler or debugger, you need to download the C ++ compiler (unless you already have on your computer C ++ compiler)
The C/C++ extension does not include a C++ compiler or debugger. You will need to install these tools or use those already installed on your computer.
Directory two: GCC via Mingw-w64 on Windows
Step One: Download Mingw-w64
For Window users, the official recommended two C ++ compiler (supplement: C ++ compatible C):
- The official document: GCC via Mingw-w64 on Windows
- Official documents: Microsoft C ++ compiler on Windows
I chose to download the GCC Via the Mingw-W64 ON Windows ,
- Official download link , wait for 5 seconds to download, the download is a compressed package
- Blue played cloud link: x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z
- Note: Mingw-w64 downloading codecs, file storage folder path names can be no spaces!
Suppose installed:D:\mingw-w64
Step Two: Configure environment variables
Right this computer> Properties> Advanced System Settings> Advanced> Environment Variables
Select Path, click Edit
Click OK also repeatedly oh, just open the pages to turn off all by determining
I assume that the installation path is: D:\mingw-w64
, the environment variable configured for:D:\mingw-w64\bin
Step 3: Check
win + r, input cmd, enter the command at the console, respectively,
g++ --version
gdb --version
So you can explain, the download is successful (if you do not see the expected output, or g ++ or gdb command is not recognized, that failure can ask me in the comments section)
Contents Three: build C ++ workspace
One: Create a new folder for storing c ++ code you write, the position to decide, is not recommended on the desktop
I direct a folder named C ++
Two: Open the folder C ++ with VSCode
-
The most crisp way: Select the folder> right-click> open by Code
-
If VSCode not registered to your right-click menu, you honestly open VSCode> file> open folder
Three: to create a c ++ file in the workspace C ++, to ensure the success of subsequent operations
Four: generating tasks.json file
tasks.json file calls g ++ compiler, create an executable file (exe file) based on source code (c ++ file)
The main menu, select Terminal> Configure Default Build Task
In the drop-down list, lists a variety of predefined C ++ compiler build tasks,
Select g ++. Exe build active file
then, VSCode will automatically generate tasks.json file in the workspace, folder on .vscode
general, need to add encoding settings in args array, or Chinese output is garbled
"-fexec-charset=GBK"
Four: compile c ++ Code
Suppose I want to run test.cpp
- Back test.cpp window
- Terminal> Run Build Task
executable file
and integrated terminal appears to the bottom panel in the code editor
Five: the implementation of the code c ++
VSCode run executable files, VSCode will prompt you to install PowerShell plug-in, follow the prompts to install
Here high probability encounter a problem: Could not load file ****** ps1, since the prohibition in this system execute the script.
You can look at an article I found, clear explanations and gives the reasons to solve Method
-
In the integrated terminal panel, open the PowerShell terminal
Click + to -
In a terminal
.\test.exe
Enter
Six: one-time compile multiple C ++ source files
Generated by default tasks.json file, one can only compile the current C ++ source file,
The tasks.json file: args array "${file}"
instead ${workspaceFolder}\\*.cpp
, can all C ++ source files in one-time compiler workspace
Contents Four: C establish a work area
The above-described operation is repeated a very high degree
- Either repeat the operation, but to choose gcc.exe build active file
- Either directly modify two values of C ++ workspace file tasks.json
"label": "g++.exe build active file"
Instead "label": "gcc.exe build active file"
;
"command": "mingw64路径\\bin\\g++.exe"
Changed"command": "mingw64路径\\bin\\gcc.exe"
mingw64 path: the path to your installation mingw64, remember to write double slash
Contents five: Debug
A: generation launch.json file
Start GDB debugger
Open VSCode, Run> Add Configuration ...
select C ++ (GDB / LLDB)
- If C workspace , select the drop-down list: gcc.exe Build and Debug the Active File
- If C ++ workspace , select the drop-down list: . G ++ EXE Build and Debug the Active File
So, VSCode will automatically generate launch.json file in the workspace, folder on .vscode
- By default, C ++ extensions do not add any breakpoints in the source code,
the"stopAtEntry"
value totrue
the debugger start-stop on the main method of debugging "cwd": "${workspaceFolder}"
When the debugger working directory for the workspace folders; change the value${fileDirname}
can be changed to the directory where the file
Contents Six: Simple talk about Microsoft C / C ++ extension of Details
Click VSCode plug-in management C / C ++
- This extension is an open source project on the github
- Repository , plug the warehouse on github
- AND DELINQUENCY , plug-issue forum on github, you can submit bug, submit solutions
- Documentation document, in fact, point to the official document on this page is VSCode extended sub-page description of plug-ins
- Code Samples code examples, we can see the new features through plug github
This sample is a simple C++ program that computes and outputs the volume of a box.
We use this example in our blog posts to illustrate new extension features.
- Offline Installers offline installer, the name may be difficult to understand, in fact, is to install the plug-in VSCode in failed, please go directly to the github download the plug-in, manually install the fight VSCode
Visual Studio Live Share is a plug-in is being expanded, and skip
Then Overview and getting started, Quick links, Questions and feedback, is the refinement of the above-mentioned website navigation
Offline installation, teach you how to manually install this plug-in
Microsoft Open Source Code of Conduct, Microsoft's open source guidelines
Data and telemetry, this plugin will collect user data passed to Microsoft to improve the user experience, anyway, I do not care
This extension collects usage data and sends it to Microsoft to help improve our products and services.
Reference article: