Compile and Run C/C++ Code in Visual Studio Code
May 302021

Compile and Run C/C++ Code in Visual Studio Code

9 antonymoberg854 May 30, 2021

Looking for IDE to compile and run C/C++ code Many beginner developers are searching for IDE to compile and run C/C++ code. Today I do not recommend an IDE to compile and run C/C++ code. Here I am talking about VS Code that is Code Editor but also behaves as an IDE with the help of Extensions. Today, In this article we will configure VS Code to compile and run C/C++ code.

Disclaimer:  This article is based on the Window but VSC is available for IOS and Linux. There is no such difference in configuration.

First of all, We have to download VS Studio from the official website. Download the VS Code according to your OS.

Besides this,  You will need other software (MinGW) that contains the C/C++ library to compile the code. you can download it from here. After download, install that software and open it. Click mingw32-gcc-compiler and click on installation as shown in the image below.

MinGW - GCC Compiler Installation
MinGW – GCC Compiler Installation

Check GCC Installed or Not

To check whether GCC is installed in your system or not, Open your CMD and type the below code:

gcc --version

If you get information like below then you have successfully installed GCC in your system.

gcc ( GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

If you did not get such information you have to set Path to Environment Variable. To set the Path to Environment variable, do the following steps:

  • Type Env in the search tool
  • Click on Edit the System Environment Variable > Environment Variables
  • Then after on the Path and Edit button
  • Click on the New button and paste your MinGW bin path. In my case, it is C:\MinGW\bin. If you have not to change anything, then your path also remains the same.
  • At last click on Save
Set Path To Environment Variables
Set Path To Environment Variables

After that check again, Whether GCC is installed or not. If you got the same error then mention the error in the comment. We will resolve your issue personally. Now we move to the VS code configuration.

VSC Configuration:

As I said at the beginning, VS Code behaves like an IDE after using an extension. So, the second step is to install the Extensions that will help us to compile and run C/C++ code in our VS Code.

This first extension that we will need to install is C/C++ powered by Microsoft. To download this extension, You can go to the extension center from Code > Preference > Extensions.  Type C++ in the Search bar, then Install the first extension powered by Microsoft or You can simply go to this link and click on the Install button that will automatically open the VS Code and Install it automatically.

VSC - C/C++ Extension download
VSC – C/C++ Extension download

Now your VS code is ready to compile and run C/C++ code but also to obtain output in one click, We need another extension. Here, We have picked Code Runner Extension. you can download this extension from the extension center or click here to install.

VSC - Code Runner Extension Download
VSC – Code Runner Extension Download

After installing the Code Runner Extension, You will see the play button at the top corner of the VS Code as shown in the below image.

VSC - Code Runner Play Button
VSC – Code Runner Play Button

You will have to configure some settings for Code Runner because it compiles and run your code in the Output section where we cannot provide input. we can see the output only.

To configure settings, Do the following steps:

  • Open the setting.json file by pressing CTRL + SHIFT + P  and type open setting and select OPEN SETTINGS (JSON) or File -> Preferences -> Settings -> Extensions -> Find "Edit in settings.json" or you can search also.
  • Just paste the below code as like below image
"code-runner.clearPreviousOutput": true,
"code-runner.preserveFocus": false,
"code-runner.runInTerminal": true,
"code-runner.saveFileBeforeRun": true
VSC - Settings.json for Code runner
VSC – Settings.json for Code runner

You can compile and run C/C++ code in Visual studio code. If you got an error then mention in the comment, I will solve your problem personally. 

About Author

Suresh Chand

I'm a web designer and developer. I have experience in PHP, WordPress, Ajax, and HTML which helps me work on both front and back end development. I have worked on over a dozen websites.

Notify of
Newest Most Voted
Inline Feedbacks
View all comments
November 12, 2020 9:10 PM

“Untitled-1.c:1: No include path in which to find iostream.h”

for the love of god, help me with this error. nothing on google helped me even after installing mingw and editing everyhing you did in your tutorial

(except these conveniences:

"code-runner.clearPreviousOutput": true,
"code-runner.preserveFocus": false,
"code-runner.saveFileBeforeRun": true,
"code-runner.terminalRoot": "/",)
Tom Rogers
Tom Rogers
February 23, 2021 5:31 AM

The end of your tutorial needs to be more precise not sure how to get that info into setting.json file. The command reference on windows 10 does not work for me.

April 7, 2021 6:58 PM

plz help me

Tanishka Kumar
Tanishka Kumar
May 30, 2021 12:40 AM

after i run or click the run button – terminal says – cannot find path(path name ) it does not exist .

August 12, 2021 6:10 AM

Running into the follow errors when running my code.
gcc.exe: error: Times: No such file or directory  
gcc.exe: error: Tables.c: No such file or directory
gcc.exe: error: Tables: No such file or directory  
gcc.exe: fatal error: no input files
compilation terminated.

Have not been able to find a solution. Any ideas?

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.

Ads Block Detector Powered by

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Disable Ad Block

Want Same System