Source: Code Academy


The Main Function

#include <iostream>

int main() 
{
  
  std::cout << "Expecto Patronum\\n";
  
}

In the code example above:

Compiling Via The Terminal

If you want to compile the program above, in the terminal use the command g++ and the name of the cpp file. The default filename output will be ./a.out.

g++ ExpectoPatronum.cpp

If you want to specify a file name output for compiling add -o FileName, like below.

g++ ExpectroPatronum.cpp -o ExpectoPatronum

Executing the Compiled Program

If you want to execute the file, use the command ./filename. The default filename is ./a.out.

./a.out
./ExpectoPatronum

Commenting

Comments are code that the machine will ignore while executing the code. Comments are purely for human readers to mark-up the code so that they or another person can understand the code more easily at a later time.