C++ needs a compiler
A computer can't read C++ directly. First a program called a compiler translates your C++ code into machine code – the 1s and 0s the computer really understands. Then the computer runs it.
Think of it like this: A compiler is like a translator. You write a letter in English (C++), the translator turns it into the language the reader speaks (machine code), and then the reader can follow it.
So running C++ always has two steps:
- Compile – turn the code into a program. If there is a mistake, the compiler stops and tells you.
- Run – start the program and see what it does.
Option 1: In your browser (no installing)
The coding challenges in this course compile and run C++ inside your web browser, using a real compiler (clang) turned into WebAssembly. Your code never leaves your computer. Open a challenge, type your code and press Run.
Tip: The first run can take a few seconds while the compiler loads. After that it is quicker.
Option 2: On your own computer
When you want to build your own projects, install a compiler:
- Windows – install Visual Studio Community (choose “Desktop development with C++”), or install MSYS2 and then the
g++compiler. - macOS – open the Terminal and run
xcode-select --install. This gives youclang++. - Linux – install g++ with your package manager, for example
sudo apt install g++.
Save your code in a file that ends with .cpp, for example hello.cpp. Then compile it and run it from the terminal:
g++ hello.cpp -o hello
./helloThe first line compiles hello.cpp into a program called hello. The second line runs it. On Windows you run it with hello.exe.
Tip: VS Code is a great free editor for C++. Install its C/C++ extension and you get colours and helpful hints.