Setting up Visual Studio Code for C/C++ on Windows

Abhinav Sinha
3 min readSep 14, 2021

--

In this article, I’ll show you how to set up Visual Studio Code for C/C++ in Windows.

We need to download two things to run our C/C++ code.

  1. MinGW compiler — To compile the code or simply translate it into machine-readable language.
  2. Visual Studio Code — IDE in which we will write our program.

Downloading MinGW Compiler

  1. Visit https://sourceforge.net/projects/mingw/ and click on download.
  2. Open the mingw-get-setup.exe file and go with the default installation. After installation MinGW Installation Manager window will shows up.
MinGW Installation Manager

3. Click on the checkbox to the left of mingw32-gcc-g++ (I have already downloaded it that’s why it is showing a green box). Select Installation > Apply Changes > Apply from the menu bar.

Installing compilers in MinGW Installation manager

Editing PATH environment variable

We need to include the directory C:\MinGW\bin in our system’s PATH environment variable to access the above directory by simply writing a command in CLI without writing the entire path.

  1. Search for “environment” in the search box. Click on Edit the system environment variables > Environment variables.
Searching for environment variables

2. After following the above steps, the Environment variables window will show up. Click on Path > Edit > New and paste C:\MinGW\bin. Click on Ok and you have successfully edited your PATH environment variable.

Downloading and setting up VS Code

As we have set up our compiler, now we’re all ready to download VSCode and write our first C/C++ program.

  1. Click here to download VS Code. After downloading open the setup file.
  2. Accept the agreement, check all the boxes shown in the picture, if you want you can also check the Create a desktop icon box and click on Next > Install. Congratulations, you have successfully installed VS Code on your machine.🎉
VS Code setup window

VS Code is all ready now to write our first code, but let’s download some important extensions to make our work even easier.

  • Head over to the Extensions tab (Ctrl+Shift+X), and search “c/c++”, click on the first extension you see i.e. C/C++ by Microsoft and then Install.

This extension adds language support for C/C++ to Visual Studio Code, including features such as IntelliSense and debugging.

C/C++ by Microsoft extension
  • Now we’ll download yet another extension. Search for “Code Runner Jun Han”, click on the first extension you see and install it.

This extension lets you run code snippets and code files for multiple languages like C, C++, Java, JS, PHP, Python, etc.

Code Runner extension

To run our code in the integrated terminal of VS Code, we need to do one last thing. Go to the Settings tab (Ctrl+,) search “code runner terminal” and check the same box as shown in the picture.

Congratulations, on following the article till the end, and successfully setting up the VSCode environment for C/C++ development. 👏

Now take a coffee, and head over to the editor to write your first program. ☕💻

--

--