How to Write And Run C and C++ Code in Visual Studio Code

How to Install VS Code or VS Code Insiders

You have to download Visual Studio Code directly from the official website: https://code.visualstudio.com/.

If you want, you can also install VS Code Insiders, and the same process is applicable for that as well.

Visual Studio Code Insiders is actually the “Insiders” build of Visual Studio Code, which contains all the latest features that are shipped daily. You can think of VS Code as the stable release and the VS Code Insiders as the Insiders release of that.

If you want to experience the latest updates instantly, then you might also try Visual Studio Code Insiders (I use it myself). For downloading VS Code Insiders, you can visit the official website for VS Code Insiders here: https://code.visualstudio.com/insiders/

Make sure to download the exact file for your operating system.

image-163
Download Page: VS Code
image-164
Download Page: VS Code Insiders

The installation process is pretty basic. But I am going to show you all the steps sequentially. For now, I am going to show you the installation process using VS Code Insiders, but everything you will see here is going to be exactly the same for VS Code as well.

Make sure to click the box on the “I accept the agreement ” box and click on Next.

image-165
Accept the agreement and click Next

Keep everything as it is. Do not change anything from here.

image-168
Click Next

Click Next. Again, simply click Next.

image-170
Click Next

Make sure to add the checkmark (✔) on all of the boxes. Then click on Next.

image-171
Check all of the boxes, and click Next

Click on Install.

image-172
Click Install

It might take a little time to finish the installation.

image-173
Let it finish…

Click on Finish.

image-175
Click Finish

Congrats – you’ve successfully installed VS Code/VS Code Insiders on your system. Now, cheers! 🥂

How to Prepare VS Code/VS Code Insiders For C and C++ Code

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.

image-178
Install C/C++ extension

Also, install C/C++ Extension Pack. It should also be verified by Microsoft.

image-179
Install C/C++ Extension Pack

Then you have to search for Code Runner and install the extension as well.

image-180
Install Code Runner Extension

Now, we need to change some settings.

image-177
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.

image-182
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 (✔).

image-184
Make sure to check the box

Now you need to restart your VS Code/VS Code Insiders. Simply close and reopen the program.

How to Test Your Code

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.

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.

Leave a Comment