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).
- Go to the official MinGW-w64 download page.
- Download the “MinGW-w64 GCC” installer for Windows.
- During installation, choose the following settings:
- Architecture: x86_64
- Threads: posix
- Exception: seh
- Build revision: latest version available
- 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.
- Press Windows + S, search for “Edit system environment variables”, and open it.
- In the System Properties window, click on Environment Variables.
- Under System Variables, find and select Path, then click Edit.
- Click New and paste this path:
C:\mingw-w64\bin - 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:
- Visit code.visualstudio.com.
- Download the Windows User Installer.
- 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.
- Open VS Code.
- Click the Extensions icon on the sidebar or press Ctrl + Shift + X.
- Search for:
C/C++ - Install the one published by Microsoft (it provides IntelliSense, debugging, and code navigation).
Step 5: Create a New C or C++ File
- Create a new folder for your project (for example,
C_Programs). - Open the folder in VS Code by going to File → Open Folder.
- Inside VS Code, create a new file and save it as
main.cormain.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.
- Press Ctrl + Shift + P and type:
Configure Default Build Task - Select C/C++: g++.exe build active file.
- VS Code will automatically create a
.vscodefolder 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:
- Open the terminal in VS Code (Ctrl + `).
- Type:
g++ main.cpp -o main - 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.