|Table of contents|
|C and C++ compilers|
|How to Install VS Code or VS Code Insiders|
|How to Prepare VS Code/VS Code Insiders For C and C++ Code|
|How to Test Your Code|
Visual Studio Code (or VS Code for short) is a very common and widely used text editor and IDE (Integrated Development Environment). You can make VS Code very powerful like an IDE using a lot of extensions.
Before approaching the process of running your first C or C++ code on Visual Studio Code, let me guide you through the process and get it all set up based on the operating system you are using on your computer.
You have to download Visual Studio Code directly from the official website: https://code.visualstudio.com/.
Download Page: VS Code
Download Page: VS Code Insiders
To install VS Code Insiders, the process is quite simple and can be done by following the steps in sequence. In this guide, I will be demonstrating the installation process using VS Code Insiders, but the steps will be the same for VS Code. Ensure that you check the "I accept the agreement" box before clicking on Next. You can find the download page for VS Code Insiders on the official website.
Accept the agreement and click Next
Keep everything as it is. Do not change anything from here.
Click Next. Again, simply click Next.
Make sure to add the checkmark (✔) on all of the boxes. Then click on Next.
Check all of the boxes, and click Next
Click on Install.
It might take a little time to finish the installation.
Let it finish...
Click on Finish.
Congrats - you've successfully installed VS Code/VS Code Insiders on your system.
First, open VS Code or VS Code Insiders.
Go to the Extension tab. Search for "C" or "C++" and install the first one that is already verified by Microsoft itself.
Install C/C++ extension
Also, install C/C++ Extension Pack. It should also be verified by Microsoft.
Install C/C++ Extension Pack
Then you have to search for Code Runner and install the extension as well.
Install Code Runner Extension
Now, we need to change some settings.
Change some settings
Click the gear box (It is called the Manage section), and then click Settings. Alternatively, you can also use the shortcut keys Ctrl + ,. You need to replace the Ctrl key with the Command key for Mac.
Type "Run code in terminal" and press Enter key
In the search bar, type "Run code in terminal" and press the Enter key.
Scroll down a little bit until you find Code-runner: Run In Terminal. Make sure that the box is checked (✔).
Make sure to check the box
Now you need to restart your VS Code/VS Code Insiders. Simply close and reopen the program.
Simply open VS Code/VS Code Insiders, open any folder, and create any file with the extension .c for the C file and .cpp for the C++ file.
After writing your code, you can run the code directly using the play button you'll find in the upper right corner.
This is how you can run any C/C++ program from VS Code/Insiders
It will compile and then run the code directly. After running a code, the code runner button would be set default to run directly. So, your computer is 100% ready for compiling and running any C/C++ programming code.