Compile: A computer can only understand machine code. A compiler can translate the C++ programs that we write into machine code. You call on the compiler by using the terminal, which is the black panel to the right of the code editor that contains a dollar sign
$. To compile a file, you need to type
g++ followed by the file name in the terminal and press enter:
The compiler will then translate the C++ program hello.cpp and create a machine code file called a.out.
Execute: To execute the new machine code file, all you need to do is type
./ and the machine code file name in the terminal and press enter. In this case, our compiled file name is
a.out. Putting it all together, we end up with the following::
The executable file will then be loaded to computer memory and the computer’s CPU (Central Processing Unit) executes the program one instruction at a time.
In our text editor, we have the Hello World program.
Click on the folder icon:
There should only be hello.cpp in there right now.
Compile hello.cpp using the terminal.
Click on the folder icon again. There should be a new a.out file in the folder, with some mysterious, alien-looking symbols inside.
We can’t understand this, but a computer can!
Execute a.out using the terminal.