How to Set Up C/C++ in Visual Studio Code on Windows 11

If you’re a programmer or student diving into C or C++, Visual Studio Code (VS Code) is one of the best editors to use — it’s lightweight, customizable, and packed with extensions that make coding much smoother.
However, VS Code doesn’t come with a compiler by default, so if you try to run C or C++ code without setting it up properly, you’ll get errors like: ‘gcc’ is not recognized as an internal or external command or ‘cl.exe’ not found’

In this guide, we’ll walk you through how to set up C/C++ in Visual Studio Code on Windows 11 step by step — from installing the compiler to configuring VS Code and running your first program.

What You’ll Need

Before we begin, make sure you have the following:

  • A Windows 11 PC
  • Visual Studio Code (you can download it here)
  • A C/C++ compiler (we’ll use MinGW)
  • Internet connection (to download extensions and packages)

Step 1: Install MinGW Compiler

VS Code doesn’t compile C/C++ by itself — you need a compiler like MinGW (Minimalist GNU for Windows).

  1. Go to the official MinGW-w64 download page.
  2. Download the “MinGW-w64 GCC” installer for Windows.
  3. During installation, choose the following settings:
    • Architecture: x86_64
    • Threads: posix
    • Exception: seh
    • Build revision: latest version available
  4. Install it to a simple directory, for example: C:\mingw-w64\

Once installation is complete, you’ll have GCC (for C) and G++ (for C++) compilers ready.

Step 2: Add MinGW to System PATH

To make sure the compiler can run from anywhere in Command Prompt, you need to add it to the PATH environment variable.

  1. Press Windows + S, search for “Edit system environment variables”, and open it.
  2. In the System Properties window, click on Environment Variables.
  3. Under System Variables, find and select Path, then click Edit.
  4. Click New and paste this path: C:\mingw-w64\bin
  5. Click OK to save.

Now open Command Prompt and type:

gcc --version

If you see the GCC version, congratulations — the compiler is installed correctly.

Step 3: Install Visual Studio Code (If You Haven’t Already)

If you don’t have VS Code installed:

  1. Visit code.visualstudio.com.
  2. Download the Windows User Installer.
  3. Follow the on-screen instructions and check:
    • ✅ Add to PATH
    • ✅ Register as default code editor

After installation, launch Visual Studio Code.

Step 4: Install the C/C++ Extension

VS Code uses extensions to enable language support.

  1. Open VS Code.
  2. Click the Extensions icon on the sidebar or press Ctrl + Shift + X.
  3. Search for: C/C++
  4. Install the one published by Microsoft (it provides IntelliSense, debugging, and code navigation).

Step 5: Create a New C or C++ File

  1. Create a new folder for your project (for example, C_Programs).
  2. Open the folder in VS Code by going to File → Open Folder.
  3. Inside VS Code, create a new file and save it as main.c or main.cpp.

Paste the following code:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, World!" << endl;
    return 0;
}

Step 6: Configure VS Code to Compile and Run Your Code

VS Code needs a tasks.json file to know how to compile and execute your code.

  1. Press Ctrl + Shift + P and type: Configure Default Build Task
  2. Select C/C++: g++.exe build active file.
  3. VS Code will automatically create a .vscode folder containing tasks.json.

If you want to run your code with a shortcut, install the Code Runner extension:

  • Search for “Code Runner” in the Extensions tab and install it.
  • Once done, you can run any C/C++ file with Ctrl + Alt + N.

Step 7: Run the Code

Now that everything’s set up:

  1. Open the terminal in VS Code (Ctrl + `).
  2. Type: g++ main.cpp -o main
  3. Then run it: ./main

You should see:

Hello, World!

That’s it — you’ve successfully compiled and run your first C++ program inside Visual Studio Code!

Wrapping Up

Setting up C/C++ in Visual Studio Code on Windows 11 is simple once you install the right tools.
With MinGW, the C/C++ extension, and Code Runner, you can compile, run, and debug your programs seamlessly — all inside one lightweight editor.

Now that your setup is ready, go ahead and start coding your first project! Whether it’s a small calculator, a game, or a data structure program — you’re all set.

Posted by Arpita

With a background in Computer Science, she is passionate about sharing practical programming tips and tech know-how. From writing clean code to solving everyday tech problems, she breaks down complex topics into approachable guides that help others learn and grow.