TExcelTAD
Home › C++ › C++ Get Started

C++ Get Started

To write C++ on your own computer you need two things: a text editor or IDE to write code in, and a compiler to turn that code into a program. On ExcelTAD you can skip the setup entirely — every example runs in the browser — but sooner or later you will want a local toolchain.

Installing a compiler

Platform Easiest option Compiler command
Windows Visual Studio Community (choose "Desktop development with C++") cl
Windows (alternative) MSYS2 + MinGW-w64 g++
macOS xcode-select --install (Command Line Tools) clang++
Linux sudo apt install g++ (Debian/Ubuntu) g++

Popular editors and IDEs: Visual Studio, VS Code with the C/C++ extension, CLion, Code::Blocks and Qt Creator.

Compile and run from the terminal

Save the following code as hello.cpp:

cpp · try it yourself
#include <iostream>

int main() {
    std::cout << "My first C++ program!\n";
}
My first C++ program!

Then compile and run it:

bash
$ g++ -std=c++20 -Wall -o hello hello.cpp
$ ./hello
My first C++ program!

What the flags mean:

  • -std=c++20 — use the C++20 language standard (the one used on this site).
  • -Wall — turn on the most useful warnings. Always read your warnings!
  • -o hello — name the output executable hello (on Windows it becomes hello.exe).

Tip: Make warnings part of your habit from day one. Add -Wextra too, and the compiler will catch many small mistakes before they turn into bugs.

What happens during compilation?

Building a C++ program happens in stages:

  1. Preprocessing — lines that start with # (like #include) are handled. The contents of <iostream> are pasted into your file.
  2. Compiling — each .cpp file is translated into machine code, producing an object file.
  3. Linking — object files and library code are joined into one executable.

If any stage fails, you get an error message and no program. Compile errors always mention a file name and line number — start reading from the first error, because later ones are often caused by it.

A program with a mistake

The code below forgets a semicolon. It is shown without a Run button because it does not compile:

cpp
#include <iostream>

int main() {
    std::cout << "Oops"   // missing ;
}

g++ reports something like error: expected ';' before '}' token. Fix the line, compile again, and you are back in business.

Using the playground

Every runnable example on this site has three buttons: Run, Reset (restore the original code) and Copy. Try changing the program below so it prints your own name:

cpp · try it yourself
#include <iostream>

int main() {
    std::cout << "Hello, my name is Ada.\n";
    std::cout << "I am learning C++.\n";
}
Hello, my name is Ada.
I am learning C++.

Test yourself

Which g++ flag selects the C++20 standard?

  1. -c++20
  2. --version=20
  3. -std=c++20
  4. -O20

Which build stage combines object files into one executable?

  1. Preprocessing
  2. Compiling
  3. Linking
  4. Interpreting

When a compile produces many errors, where should you start?

  1. The last error
  2. The first error
  3. Any random error
  4. The warnings only