Learn C++ in the browser here, then move to a local toolchain for full projects. This guide covers running, debugging and building C++ in VS Code.
Install a compiler
- •Windows: install MSYS2 (msys2.org) then
pacman -S mingw-w64-x86_64-gcc, or install Visual Studio with the "Desktop development with C++" workload. - •macOS:
xcode-select --installgives you Clang. - •Linux:
sudo apt install g++ gdb(ordnf install gcc-c++ gdb).
Verify: g++ --version
VS Code
Install the C/C++ extension by Microsoft for IntelliSense and debugging. For larger projects also add the CMake Tools extension.
Write, compile and run
Create hello.cpp:
#include <iostream>
int main() {
std::cout << "Hello, C++!" << std::endl;
}Compile and run:
g++ -Wall -std=c++17 hello.cpp -o hello
./helloDebug it
Press F5; VS Code creates a launch.json for gdb/lldb. Set breakpoints, inspect memory and step through pointer logic. Always compile with -g so debug symbols are available.
Build a project with CMake
For more than one file, use CMake:
cmake -S . -B build
cmake --build buildA CMakeLists.txt describes your targets and dependencies once, and CMake generates the right build files for any platform — the standard way real C++ projects are built.