Why should you use visual studio code ?


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.



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.



Step 1: Download Visual studio code.


Type vscode on your browser and click on the first link of the page, or just click here.



install vscode



vscode



Now download the installer according to your operating system.



Step 2: Install vscode



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



install



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



Step 3: Download extensions for visual studio code.



vscode editor



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


Now click on the 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.



extension



Install the extension.



c



Now we have to install another extension called Code Runner.



code runner



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.



Step 4: Download MinGW



Type MinGW on google and choose the following first link as shown in the image below or Click Here.



mingw



Now click download.



download



Step 5: Install MinGW



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.



mingw



mingw install



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



install



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



install



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



install



And then click on Apply.


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



install



Click close and close the installer.



Step 6: Copy Bin Path



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



bin path



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



bin path



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



Step 7: Environment Variables



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



variable



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



variable



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



variable



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



variable



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



variable



Now click ok till there are no pop ups left.



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



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



cmd



g++ --version



cmd



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


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



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



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


Open vscode.


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


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



vscode



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


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



vscode



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



hello world



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



Step 9: Run the code.



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



terminal



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.

author image

Narottam Sahu

I'm a self-taught web developer. Other than coding, I enjoy networking with like minded people, drawing, and playing guitar in my spare time.

Join the conversation