Setup VS Code for C++ Development

Hello and welcome in this post we are going to know how you can Setup VS Code for C++ Development and programming. If you are not new to programming then you must know that Visual Studio code is a code editor built by Microsoft. This is one of the most advanced code editor used by most of the developers. In this post we are going to configure Visual Studio code in such a way that it will provide us maximum things for C++ programming.

Here I am going to discuss about everything that you will need to setup Visual Studio code for C++ programming productivity. Not only C++ programming we can also do C programming once we had set up our Visual Studio code. So it means that in this post we are going to figure out productivity setup in Visual Studio code for two programming languages.

Setup VS Code for C++ Development: –

The first thing that we need is code editor itself you have to to download visual Studio code from its official website. So go ahead and use this link to download Visual Studio code and the installation process is very simple you can just follow on screen instruction within few minutes.

Install C++ Compiler In VS Code: –

The next step is to install C++ compiler in your machine. The mostly used compiler for compiling the code is a MinGW. You also have to download same compiler using this link.  From that page you have to navigate to download page and you will be given several downloadable files. If your computer is of 64 bit then download 64 bit executable exe file If you are using Windows or if you are using any other platform than simply download the suitable file.

Open downloaded file and install the MinGW Compiler. Once you had done this you can move forward and add MinGW path in system variables.

Add System Variables: –

No the next step is to add MinGW compiler part 2 your system variable so that you can access it from anywhere in the system. We will need this thing while running and building C++ file from Visual Studio code.

  1. Open MinGW folder (The folder where you had installed MinGW)
  2. Open bin folder from there and copy path of the folder from top bar.
  3. Now press windows button and search for Environment Variables.
  4. Now paste the copied path same as shown in below picture.

As shown in above picture double click on Path and enter new path and paste the copied path there. Now we have successfully installed and configured C++ compiler it’s time to test it. To test whether C++ compiler is successfully installed or not a run the below command from command prompt.

g++ –version

gdb –version

If above command return to the version of C++ compiler that you have installed it means that everything is ok.

Install VS Code Extension: –

To make your coding easy we will now install extension in Visual Studio code to enable intelligence. We will install just one plugin to do this and that plugin name is C/C++ that is freely available in Visual Studio Marketplace.

You can simply search for C++ in Visual Studio extension panel and simply click on install button to install it.  Once you have done this you can simply start coding. Create a new file with extinction .c or .cpp according to a programming language and start coding. In next paragraph we are going to discuss about how we can compile and run this program or code that we will right directly through Visual Studio code.

Compile & Run: –

Now the only step left is to compile and run the code. How does this compiling and running work let me explain it simply once we write code we need to give it to compiler and compiler will give back as the output. We can simply use terminal commands send this code to to compiler. But before sending it we need to configure compiler with vs code.

Configure Compiler: – To configure compiler with Visual Studio code simply press CTRL + SHIFT + B. For the first time when you hit the shortcut buttons you will be asked to select your default compiler that list you have to select C/C++: g++.exe build active file and press enter.

Running Code: – To run your code simply press again CTRL + SHIFT + B. It may take some time depending upon your codebase size and once this is done you will be given an executable file with .exe extinction and same name as your .c or .cpp file. To run this executable file you simply need to to enter its name in terminal. Like if your code file name is hello.c and you have successfully built it using the shortcut you can execute it by entering hello.exe directly in terminal that is provided by vs code.

In above picture if you look it carefully you will see that I have executed a file named specific_name.exe and its code based file name is specific_name.c so now you can simply run code directly from terminal with single command.

Also Read: – Best Linux Distro 2021

Conclusion: –

In this post we discussed about how you can setup your Visual Studio code for programming in C/C++ languages. How you can install intelligence in Visual Studio code to support these languages. We also learnt how to install compiler and configure the compiler with Visual Studio code. So I hope that this post was helpful for you and you found this content informative.



Please enter your comment!
Please enter your name here