Hey friend! If you’re just starting your coding journey and wondering how to set up C++ on VS Code, you’re in the right place! Setting up C++ correctly is the first real step to writing and running your own programs and trust me, it’s easier than you think.
Whether you’re a student preparing for coding competitions or someone exploring system programming, Visual Studio Code for C++ development is a beginner-friendly, lightweight, and powerful option.
In this guide, we’ll walk through the exact steps to install VS Code, set up the MinGW C++ compiler, write your first program, and run it using the terminal — all with examples to make learning smooth and fun.
Not sure what C++ is or why it’s still one of the most powerful languages? Check out Part 1: Day 1: What Is C++? A Complete Guide for Beginners to understand its real-world use cases and why it’s a must-learn language in 2025.
Think of this like setting up your kitchen before you start cooking. You need your tools (VS Code), your ingredients (compiler), and a good recipe (your first program).
By the end of this post, you’ll have everything set up and will be running your first C++ program — “Hello, World!”
Let’s go!
What You Need to Set Up C++ on VS Code
To write and run C++ code, you’ll need:
• VS Code – a lightweight but powerful text editor
• MinGW – a compiler to convert your code into machine language
• Basic terminal commands – don’t worry, I’ll walk you through it
Step 1: Download and Install Visual Studio Code
🌐 Go to https://code.visualstudio.com
Click Download for Windows (or macOS/Linux, if you’re using those).
Run the installer and follow the usual install steps → Next → Next → Finish.
Example: VS Code is like your notebook where you’ll write your programs. It’s smart, fast, and comes with cool features like auto-suggestions and debugging.
Step 2: Install MinGW C++ Compiler
Why you need it:
Your code is just text. The compiler turns it into something your computer can actually understand and run.
Here’s how to get it:
1. Visit:
https://www.mingw-w64.org/downloads/
2. Choose the MinGW-w64-builds option
(WinLibs or SourceForge is fine)
3. Settings to choose:
Architecture: x86_64
Threads: posix
Exception: seh
Build revision: latest
4. Download and install it (choose a folder like C:\mingw-w64).
Step 3: Add MinGW to Your System PATH
This step is like telling Windows where to find your “C++ chef” (compiler) so it can cook your code.
Steps:
- Copy the path to the bin folder inside your MinGW installation.
Example: C:\mingw-w64\bin - Press Windows Key, search Environment Variables → Click “Edit the system environment variables”
- In the dialog box, click Environment Variables
- Under System Variables, find and click Path → Edit → New → Paste the bin path → OK
- Open a new terminal or command prompt and type:
g++ –version
✅ If you see the version info, MinGW is working!
Step 4: Install C++ Extensions in VS Code
Launch VS Code. Go to the Extensions icon (or press Ctrl+Shift+X), then search and install:
✅ C/C++ by Microsoft
✅ (Optional) Code Runner – makes running code a one-click job
Step 5: Write Your First C++ Program
Let’s make our first file:
1 Open VS Code
2 File → New File → Save as hello.cpp
3 Paste this code:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!";
return 0;
}
What’s going on?
#include <iostream> – brings in input/output stuff
main() – the entry point of your program
cout – prints to screen
Example: This is like your very first recipe boiling water and making noodles. It’s simple, but it works!
Step 6: Compile and Run in VS Code
1 Open a terminal in VS Code
(Terminal → New Terminal OR press `Ctrl+“)
2 Type the following to compile:
g++ hello.cpp -o hello
This creates an executable file named hello.
3 To run it:
./hello
✅ You should see:
Hello, World!
Congrats! You just ran your first C++ program!
Common Errors (And Quick Fixes)
Error Fix
g++ not recognized Make sure MinGW is added to your PATH
Terminal shows nothing You may not be in the right directory — use cd to navigate
Code not compiling Check for typos: semicolons ; matter a LOT in C++
What’s Next?
You’re now fully set up to write real C++ programs. In the next post (Day 3), we’ll explore:
Variables
Data types
Taking input from users
Writing simple math programs
It’s like learning how to use different ingredients after setting up your kitchen.
Real-Life Uses of This Setup
💻 Students use this setup for coding assignments and Olympiads
🧑💼 Interview prep often starts in VS Code with C++ logic questions
🕹️ Game developers use C++ for engines like Unreal, and many use VS Code as their daily editor
Recap: What You Did Today
✅ Installed VS Code
✅ Installed MinGW compiler
✅ Set up the environment path
✅ Wrote your first “Hello World” program
✅ Ran it from the terminal
You’re no longer a beginner — you’re a coder in action.
FAQs
Do I have to repeat this every time?
Nope! Once you’ve installed and set up everything, you can reuse it for all your projects.
Can I use this on Linux or macOS?
Yes! The setup process is similar, but uses g++ which is usually pre-installed or can be added with brew or apt.
Is VS Code better than Code::Blocks or Turbo C++?
For beginners, VS Code is faster, modern, and easier to customize. It’s the most beginner-friendly and widely used editor today.
Conclusion
Learning to code is like learning to build. Today, you’ve built your workbench and tools. Tomorrow, we’ll start crafting your first real projects.
📌 Bookmark this post so you can return anytime.
Subscribe or follow to get notified for Day 3: Variables, Inputs & Outputs in C++.
Also, if you’re learning Python too, don’t miss my Learn Python in 30 Days – Part 1: What is Python and How to Start (With Real-Life Analogies)