C++ Get Started
Install a C++ compiler, set up your editor, and run your first program from scratch.
To start writing C++ code, you need just two things:
- A C++ compiler — translates
.cppsource into an executable. - A text editor or IDE — VS Code, CLion, Code::Blocks, or even Notepad.
| OS | Recommended Compiler | Install Command |
|---|---|---|
| Windows | MinGW-w64 (GCC) | Use the MSYS2 installer |
| macOS | Clang (Xcode CLT) | xcode-select --install |
| Linux | g++ | sudo apt install g++ |
Verify your install:
bashg++ --version
You should see something like g++ (GCC) 13.2.0.
Step 1. Create a file hello.cpp:
cpp#include <iostream> using namespace std; int main() { cout << "Hello, Codekilla!" << endl; return 0; }
Step 2. Compile:
bashg++ hello.cpp -o hello
Step 3. Run:
bash./hello # macOS / Linux hello.exe # Windows
Hello, Codekilla!
- The compiler read
hello.cpp. - It translated the C++ into machine instructions for your CPU.
- It linked in the standard library (so
coutworks). - It produced an executable binary called
hello.
You don't need a runtime (like the JVM or Python interpreter) — the binary runs natively.
| Flag | Purpose |
|---|---|
-o name | Set output filename |
-Wall | Show all warnings (highly recommended) |
-std=c++17 | Use the C++17 standard (or c++20, c++23) |
-g | Include debug symbols (for gdb) |
-O2 | Optimise for speed |
A safe default for learning:
bashg++ -std=c++17 -Wall -g hello.cpp -o hello
- Install VS Code.
- Add the C/C++ extension by Microsoft.
- Add Code Runner (optional, gives you a one-click ▶ Run button).
- Open your folder, create
hello.cpp, hit ▶ — you're coding.
Don't want to install anything? Use Codekilla's online C++ compiler — write code in the browser, click Run, see output. Perfect for learning on the go.
- Compiling but not running —
g++ hello.cpp -o helloonly creates the binary; you still need./helloto execute. - Wrong filename — Save as
hello.cpp(not.cor.txt);.cppis the standard extension. g++not found — PATH not set after install. Restart the terminal or add the compiler'sbin/to PATH.- Mixing tabs/spaces — Doesn't break C++ (it's not Python), but inconsistent indentation looks awful.
- Skipping
-Wall— You'll miss bugs that the compiler could catch for free.
- Install + compile — Set up g++ on your machine and compile
hello.cpp. Confirm the binary runs. Hint: check version withg++ --version. - Filename change — Compile with
g++ hello.cpp -o greeterand run./greeter. Hint: name doesn't have to match source. - Add a warning — Add an unused variable like
int x;and compile with-Wall. Hint: warning will say "unused variable x". - Print three lines — Modify the program to print 3 lines of your choice and re-run. Hint: 3
coutstatements.
Think Like a Programmer: Master your toolchain first. Spending 30 minutes to set up
g++ -Wall -std=c++17saves you from days of confusing bugs later.
Quick recap quiz?
We'll generate 5 MCQs from this lesson and check your understanding instantly. Takes ~30 seconds.
Program
#include <iostream>
using namespace std;
int main() {
cout << "Hello, Codekilla!" << endl;
cout << "My first C++ program." << endl;
return 0;
}