Hello World in C++

C++ is a widely used programming language for many things. This tutorial just gives you the basic “Hello World!” program and how to run it on a Unix system. For a good book on learning C++ see here.

Hello World!

#include <iostream>
int main()
{
    std::cout<<"Hello World!\n";
}

Save this as hello.cpp using your favourite plain text editor.

Compiling C++ for Linux/FreeBSD

Install either the gcc or clang (recommended) package.
You will need to know how to use the command line.
From now on c++ refers to clang++ if you installed clang and g++ if you installed gcc.
Navigate to the directory where hello.cpp is saved using the command line, and execute

c++ -std=c++11 hello.cpp -o hello

This will execute the compiler, in C++11 mode (i.e. Supporting the latest version of C++, which is C++11), compile hello.cpp into machine code, and store the final resulting executable as hello.
To execute the result run

./hello

and Hello World! will be printed to your command line.