[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (2024)

Narottam04

Posted on • Updated on

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (2) [Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (3) [Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (4) [Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (5) [Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (6)

#cpp #programming #vscode #cprogramming

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.

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (7)

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (8)

Now download the installer according to your operating system.

Step 2: Install vscode

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

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (9)

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

Step 3: Download extensions for visual studio code.

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (10)

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.

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.

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (11)

Install the extension.

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (12)

Now we have to install another extension called Code Runner.

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (13)

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 following first link as shown in the image below or Click Here.

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (14)

Now click download.

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (15)

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.

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (16)

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (17)

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

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (18)

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

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (19)

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

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (20)

And then click on Apply.

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

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (21)

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.

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (22)

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

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (23)

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 system on your control panel just type 'system' on the search bar which you can find in top right corner of the control panel.

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (24)

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

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (25)

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

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (26)

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

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (27)

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

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (28)

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 search button near the bottom left of windows and search for command prompt.

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (29)

g++ --version

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (30)

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 the 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 lets 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.

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (31)

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

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

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (32)

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

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (33)

#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'.

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (34)

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.

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (35)

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

Top comments (8)

Subscribe

Karthik Nandula

Karthik Nandula

Udemy Instructor and Alexa Skills Developer.

  • Location

    United Kingdom

  • Joined

Jul 13 '22

  • Copy link

Just one thing I'd add to this, after I installed mingw, I was trying to run my c file but it didn't work because my vs code needed a restart, so if vs code was already open before installing mingw, just give vs code a restart and everything should work.

Nnennajohn-rain

Nnennajohn-rain

  • Education

    University of Cape Coast, Ghana

  • Joined

Sep 26 '22

  • Copy link

This was super helpful, you're amazing! Thank youuuu.

Mohamed Abdulla

Mohamed Abdulla

An enthusiastic developer as well as student.

  • Location

    Remote

  • Joined

Sep 26 '22

  • Copy link

really helpful
__

Mohammad Zakaria

Mohammad Zakaria

  • Joined

May 25 '22

  • Copy link

thank you...i set up my vs code following this guide...

Narottam04

Narottam04

const Bio = ["React Native Developer","Web Developer", "Freelancer" ,"UI/UX Designer" ,"Technical Writer"]

  • Email

    webdripdev@gmail.com

  • Location

    Mumbai, India

  • Education

    Currently pursuing bachelor's in computer science

  • Joined

May 26 '22

  • Copy link

I'm glad, you found it helpful.

divyansh343

divyansh343

Young developer

  • Location

    Chhindwara,Mp,India

  • Work

    Student at University

  • Joined

Apr 6 '22

  • Copy link

it's really helpful. its worth reading

Narottam04

Narottam04

const Bio = ["React Native Developer","Web Developer", "Freelancer" ,"UI/UX Designer" ,"Technical Writer"]

  • Email

    webdripdev@gmail.com

  • Location

    Mumbai, India

  • Education

    Currently pursuing bachelor's in computer science

  • Joined

Apr 7 '22

  • Copy link

Glad you find it helpful!

Reihane

Reihane

A learner!

  • Location

    Iran

  • Education

    currently, pursuing bachelor's in electrical engineering

  • Work

    student

  • Joined

Jul 31 '22

  • Copy link

Thank you!
when I run my code, I see this error:

'g++' is not recognized as an internal or external command,
operable program or batch file.

What am I supposed to do?

For further actions, you may consider blocking this person and/or reporting abuse

[Step By Step Guide] How to set up visual studio code for C and C++ programming 2021. (2024)

References

Top Articles
Latest Posts
Article information

Author: Melvina Ondricka

Last Updated:

Views: 5600

Rating: 4.8 / 5 (68 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Melvina Ondricka

Birthday: 2000-12-23

Address: Suite 382 139 Shaniqua Locks, Paulaborough, UT 90498

Phone: +636383657021

Job: Dynamic Government Specialist

Hobby: Kite flying, Watching movies, Knitting, Model building, Reading, Wood carving, Paintball

Introduction: My name is Melvina Ondricka, I am a helpful, fancy, friendly, innocent, outstanding, courageous, thoughtful person who loves writing and wants to share my knowledge and understanding with you.