Setup

You can code C++

In this tutorial, we will install GCC (tailored for Linux/Mac users).

Installing GCC

Install gcc:

# On linux
# build-essential includes gcc, g++ and make
sudo apt install build-essential

# On mac
brew install gcc

Verify your gcc installation:

gcc --version

Compiling your code

Save the following code, for example as hello.cpp.

#include <cstdio>

int main() {
  printf("Hello, world!\n");
  return 0;
}

Compile your code using gcc.

You can specify the name of your output file using -o <filename>; otherwise gcc will use a.out as the default output filename.

# it will output an executable file named `hello`
gcc helo.cpp -o hello

Run the code. For the example above, it should print Hello, world!.

./hello

References