You can learn C++ fundamentals right here in the browser using the BaseCodeByte notebook — no setup required. But once you're ready to write larger programs, you'll want a real local development environment. Here's how to set one up.
Step 1: Install a compiler
*Windows:* Install MinGW-w64 via MSYS2 (msys2.org). After installation, run: pacman -S mingw-w64-x86_64-gcc. This gives you g++, the GNU C++ compiler.
Alternatively, install Visual Studio Community (free) which includes MSVC, Microsoft's C++ compiler.
*macOS:* Install Xcode Command Line Tools: xcode-select --install. This gives you Clang, which fully supports modern C++.
*Linux:* Most distributions include g++. If not: sudo apt install g++ (Ubuntu/Debian) or sudo dnf install gcc-c++ (Fedora).
Verify your installation: g++ --version (or clang++ --version on macOS)
Step 2: Install VS Code
Download VS Code from code.visualstudio.com. Install the C/C++ extension by Microsoft (search "C/C++" in the Extensions sidebar).
Step 3: Write and compile your first program
Create a file called hello.cpp:
#include <iostream>
int main() {
std::cout << "Hello, C++!" << std::endl;
return 0;
}Compile it from the terminal:
g++ hello.cpp -o hello
Run it:
./hello # macOS/Linux hello.exe # Windows
You should see: Hello, C++!
Step 4: Configure VS Code build tasks
In VS Code, press Ctrl+Shift+P, type "Tasks: Configure Default Build Task", select "g++: build active file". This creates a tasks.json that lets you build with Ctrl+Shift+B.
Press F5 to debug. VS Code will ask you to configure launch.json — accept the defaults for C++.
Useful flags
Always compile with warnings enabled during development:
g++ -Wall -Wextra -std=c++17 hello.cpp -o hello
- •-Wall: enable all common warnings
- •-Wextra: enable extra warnings
- •-std=c++17: use the C++17 standard
What's next
Once your environment is working, try expanding the hello.cpp program: add a variable, a loop, a function. The goal is to feel comfortable with the compile → run → fix cycle before moving to larger programs.