[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021.
Tags: cpp, programming, vscode, cprogramming
Published: 2021-06-02 07:13:16

## Why should you use visual studio code ?

<br />

Visual Studio Code is a free source-code editor made by Microsoft for Windows, Linux and macOS. Features include support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git.

It currently supports hundreds of programming languages and file formats. Several common languages come supported by default (JavaScript, HTML, CSS, etc), and others gain support by adding integrated extensions. If you find a language that isn't supported by an existing extension, the open nature of the extensions system means you can build one.

<br /> <br />

In this blog post you will learn how to set up visual studio code on your local environment for C and C++, this can get tricky but if you follow step by step you can set it up easily.

<br /> <br />

## Step 1: Download Visual studio code.

 <br />

Type vscode on your browser and click on the first link of the page, or just [click here](https://code.visualstudio.com/download).

<br /> <br />

![install vscode](https://drive.google.com/uc?id=1L-f2VD45-Av5UW3162EesA2sALbxDZl8 "install vscode")

<br /> <br />

![vscode](https://drive.google.com/uc?id=1kFW7HBLYKxLfIK52G153YK8-wHu77z0F "vscode")

<br /> <br />

Now download the installer according to your operating system.

<br /> <br />

## Step 2: Install vscode

<br /> <br />

This step is easy, accept the agreement and click next.

<br /> <br />

![install ](https://drive.google.com/uc?id=1HDjUBHvpFeHs7C-xmhigulJXRq3Fvwtt "install")

<br /> <br />

Check the following options as shown in above image and click next and install.

<br /> <br />

## Step 3: Download extensions for visual studio code.

<br /> <br />

![vscode editor](https://drive.google.com/uc?id=1QNyzG3PTtSlp8pkLzSvWk6xknje2IvtA "vscode editor")

<br /> <br />

Once you have installed visual studio code, now its time to install some extensions. Click on the button where red arrow is pointing in above image.

 <br />

Now click on C/C++ extension from Microsoft as shown in the below image. If you don't see the extension search C/C++ and you will find it.

<br /> <br />

![extension](https://drive.google.com/uc?id=1H71XGWoFeIDHARkEkTivxlyrctP6rs-l "extension")

<br /> <br />

Install the extension.

<br /> <br />

![c](https://drive.google.com/uc?id=1K1-8cm3bWnlf08sDt_B6hvLdnrqJ_yv9 "c")

<br /> <br />

Now we have to install another extension called Code Runner.

<br /> <br />

![code runner](https://drive.google.com/uc?id=1qrf82WbMV2_fw36kBtVKLsljmLbz51k_ "code runner")

<br /> <br />

Now we have successfully installed code editor but we need a compiler to compile and output our code, for that we will be installing MinGW.

<br /> <br />

## Step 4: Download MinGW

<br /> <br />

Type mingw  on google and choose following first link as shown in the image below or [Click Here](https://sourceforge.net/projects/mingw/).

<br /> <br />

![mingw](https://drive.google.com/uc?id=1zZl3khQIfqj5bYIBtS1U1zzz4vBJfuNi "mingw")

<br /> <br />

Now click download.

<br /> <br />

![download](https://drive.google.com/uc?id=1lZvHP2iKch1pIDzAnPrMzFCfKcpx5EAA "download")

<br /> <br />

## Step 5: Install MinGW

<br /> <br />

Open the installer, you should see something like the below image. Click on install and choose your directory where the software should be installed and click continue.

<br /> <br />

![mingw](https://drive.google.com/uc?id=1_8waY_FBb0gmJyetYsHjjdoy16IWIezL "mingw ")

<br /> <br />

![mingw install](https://drive.google.com/uc?id=1OnRnb_MI9DKKFhiiw09sRhTBb9U1t0vg "mingw")

<br /> <br />

After installing, click on continue and right click on every checkbox and choose mark for installation.

<br /> <br />

![install](https://drive.google.com/uc?id=1yW512J92eHkBNFg59yAJ63V0wfaOXIbu "install")

<br /> <br />

After checking all checkboxes you should see something like image below.

<br /> <br />

![install](https://drive.google.com/uc?id=1Hkop1Av7Iv1RwzUc54A11Dh3LboxPihj "install")

<br /> <br />

Now click Installation on top left corner and then choose Apply Changes. You should see something like shown in the image below.

<br /> <br />

![install](https://drive.google.com/uc?id=1fsfS6zP8wRTcForq88q6FkRgeK_6fTfJ "install")

<br /> <br />

And then click on Apply.

 <br />

Once you complete the installation, you should see something like the image below.

<br /> <br />

![install](https://drive.google.com/uc?id=1r43biwjVFQ3PTt8kR6shbzFnMhukFtzx "install")

<br /> <br />

Click close and close the installer.

<br /> <br />

## Step 6: Copy Bin Path

<br /> <br />

Now open 'This PC' and open 'local Disk C' you should see mingw file and click on bin folder.

<br /> <br />

![bin path](https://drive.google.com/uc?id=1ybUfwYJGiubNQK1w50j20EnuajsTkJ8j "bin path")

<br /> <br />

Now you have to copy the folder destination which is above the page as shown below.

<br /> <br />

![bin path ](https://drive.google.com/uc?id=1OrjYYBKrm-lkdHNx_vAKwulX3jsJnKEu "bin path")

<br /> <br />

Now right click and copy or just press 'Ctrl + C' on your keyboard.

<br /> <br />

## Step 7: Environment Variables

<br /> <br />

Open 'Control Panel' from your start menu and click on System. If you don't find system on your control panel just type 'system' on the search bar which you can find in top right corner of the control panel.

<br /> <br />

![variable](https://drive.google.com/uc?id=19x2SwymD48LEWppY__uDNOiTFdohK50D "variable")

<br /> <br />

Click on Advanced system setting on right side you should see system properties as shown in the image below.

<br /> <br />

![variable](https://drive.google.com/uc?id=1bTzccMlsLHb6XrIhxm360eHgbAS3FQmx "variable")

<br /> <br />

Now click on Environment Variables you should see something as shown in the image below.

<br /> <br />

![variable ](https://drive.google.com/uc?id=1EphBQN4c_t-Gv-8hZm_No68XRHwCHLg6 "variable")

<br /> <br />

Now click on the path in system variable and click on edit as shown in the image below.

<br /> <br />

![variable ](https://drive.google.com/uc?id=1qNo7ATQUmz09HKPlUhYlYODM0BmRyH5z "variable")

<br /> <br />

Now click on new and paste the bin path that we have copied in the previous step and then click Ok.

<br /> <br />

![variable ](https://drive.google.com/uc?id=1mTcrQyWxSCp7edJxH9t6hpgoH36mZiiG "variable")

<br /> <br />

Now click ok till there are no pop ups left.

<br /> <br />

## Step 8: Let's check if MinGW has been successfully installed or not.

<br /> <br />

Click on search button near the bottom left of windows and search for command prompt.

<br /> <br />

![cmd](https://drive.google.com/uc?id=13JdX4V36SzyIm29vlnt7XZcGqiayxJXA "cmd")

<br /> <br />

```powershell
g++ --version
```

<br /> <br />

![cmd](https://drive.google.com/uc?id=1wUGldkS198DIDdcIMx1rX0qTg8oaz-q5 "cmd")

<br /> <br />

And if you see something like the image above, voila! we did it.

 <br />

🛑 🛑 If you get some error don't worry just reinstall mingw as shown in the step 4 and step 5 and it should solve the problem.🛑🛑

<br /> <br />

## Step 8: Let's write our first program in C++

<br /> <br />

Hurray! we have successfully set up vscode for C and C++ now lets test it by writing our first program in vscode.

 <br />

Open vscode.

 <br />

Click on 'File' in upper left section and choose 'Open Folder'.

 <br />

Lets make a new folder in dekstop and select the folder.

<br /> <br />

![vscode](https://drive.google.com/uc?id=1-poPFVl2ME8rAhE2V-1H9ADMaKBy9fCI "vscode")

<br /> <br />

Now click on the document symbol in the side bar. If you dont see a sidebar just press Ctrl + B on keyboard.

 <br />

Now make a file with a extension of .cpp as shown in the image below

<br /> <br />

![vscode](https://drive.google.com/uc?id=1V6n9hOea8PG2XbT0KYRYLPplYSf5czh7 "vscode")

<br /> <br />

Now lets type our first code. You can copy and paste the code that I have provided below.

<br /> <br />

![hello world](https://drive.google.com/uc?id=1A_AoHzypt3SJyqbwpCPVU0VUvPH4oFfV "hello world")

<br /> <br />

```cpp
#include<iostream>
using namespace std;
int main()
{
    cout<<"hello world";
}
```

<br /> <br />

## Step 9: Run the code.

<br /> <br />

Right click and click on run or press keyboard shortcut 'Ctrl+Alt+N'.

<br /> <br />

![terminal](https://drive.google.com/uc?id=1YwHoSHS9DYWlbLbXsKSDeF4P5WXcMkZQ "terminal")

<br /> <br />

And there you go you have written your first program in C++, I hope this tutorial was helpful if you are facing any problem while installing let me know in the comment section or email me at blog.webdrip.in.


<a href="https://www.buymeacoffee.com/narottam"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=narottam&button_colour=FFDD00&font_colour=000000&font_family=Poppins&outline_colour=000000&coffee_colour=ffffff"></a></a>

<br /> <br />

Get more insights like this on my blog, https://blog.webdrip.in.