How to Set up Visual Studio Code for C and C++ Programming

Today, we will show you how to setup Visual Studio Code for C and C++ Programming.

C/C++ is one of the most widely used programming languages in the world and Microsoft Visual Studio is one of the most widely used IDEs to code in C/C++.

Visual Studio Code is a popular development tool that is ideal for C and C++ programming. It is an open-source tool and has a feature-set similar to Visual Studio. 

Visual Studio Code is a light-weight source code editor developed by Microsoft. It’s available on Windows, macOS, Linux, and other operating systems. 

This blog will talk about how we can integrate Visual Studio with Code, the new lightweight and fast editor from Microsoft. This blog will be helpful for those who would like to code using C/C++ in Visual Studio.

Here is how to download visual studio code-

 How to download Visual Studio Code in Pc

The procedures to install Visual Studio Code are as follows.

  • So, let’s get started installing Visual Studio on your Windows 10 operating system. First, you’ll need to download it from here.

Visual Studio code Download

  • After you’ve downloaded Visual Studio Code, simply double-click on the downloaded file to install it.
  • Click next after accepting the licensing agreement and selecting your installation directory. You can also leave it to default. And then click on next.
  • Now, as seen in the screenshot below, check all of the options in this stage (important). After that, click next and then install.

After the Vs code installation is complete, click the Finish button.

How to add MinGW bin directory to the system path

Now you need to download the MinGW 64 compiler, If you don’t know how to download and install MinGW 64 compiler Check out this post

Our next step is to add the MinGW bin directory to the system path-

Follow these instructions, then add the directory where MinGW plus bin is installed. If you install MinGW in C: for example, you must add C:mingwbin to your path.

  • Right-click My Computer on the desktop and select Properties.
  • Select the Advanced tab in the System Properties window.
  • Click the Environment Variables button in the Advanced section.
  • Finally, choose the Path variable in the Systems Variable area of the Environment Variables window and click the Edit button.
  • Replace the path lines with the paths you want the machine to be able to access. A semicolon is used to separate each directory, as seen below.

C:\Program Files;C:\Winnt;C:\Winnt\System32;c:\mingw\bin

Now we will download some helpful extensions to Visual Studio Code to make your c or c++ code run faster.

Installing extensions in visual studio code

We will install these two extensions

  1. C/C++
  2. Code Runner

Simply launch Visual Studio Code and select the button displayed below to get these extensions.

How to Set up Visual Studio Code for C and C++ Programming in Windows

  • And then type in c/++ and click the install button to install the extension.
  • Code runner will be the next extension we install.
  • To get this extension, search for code runner as you did before, then select the install option and wait for it to finish.
  • Restart Visual Studio code after installing both extensions.

After downloading the code runner extension is that if you need to receive input from the user, we can’t receive the input through this output tab because it’s read-only. As a result, we’ll need to come up with a solution for this one.

To solve this error follow the given instructions

  • To begin, click on the file that has at least the top corner visible.
How to Set up Visual Studio Code for C and C++ Programming in Windows
  • Now go to preferences and select settings from there.

How to Set up Visual Studio Code for C and C++ Programming in Windows
  • Select Extensions from the drop-down menu. Now, if you scroll down, you’ll see run code configuration, which you may click on.

How to Set up Visual Studio Code for C and C++ Programming in Windows
  • Scroll down again, and here you must check the run in the terminal.
  • After that, press Ctrl+S to save the settings and exit them.

Running the first program in Visual Studio code

Now that we’ve set up Visual Studio Code for C and C++ programming, we’ll need to test that Gcc and Visual Studio Code are both working by running a basic C program.

To do so, open any folder on your computer. Now, right-click and select Visual Studio Code from the drop-down menu.

How to Set up Visual Studio Code for C and C++ Programming in Windows

Create any file called demo.cc to run your first program.

And Write a simple c or c++ program as 

// Your First C++ Program

#include <iostream>

int main() {

    std::cout << “Hello World!”;

    return 0;

}

NOW press Ctrl+s and then click the run button to save it.

Congratulations on successfully setting up Visual Studio Code for C and C++ programming languages if your program runs.

Conclusion

Visual Studio Code is a free and open-source code editor from Microsoft that has extensions that make it a great tool for programming.

This blog Showed you how to set up Visual Studio Code for C and C++ Programming and how to set up some extensions for C and C++ programming.

And also show you helpful extensions which will help you to run code more efficiently.

If you have any doubt related to visual studio code comment down,

Leave a Comment

NASA loses two hurricane monitoring satellites on launch SpaceX To Launch With NASA’s Supplies To International Space Station NASA to launch 3 rockets from private Australian space port NASA Delays ISS Cargo Launch Following Dragon Fuel Leak Tesla Model Pi smartphone 2022 : Everything you need to know