Skip to content

Hello World in C++

I’m going to show you something simple and fundamental for every C/C++ programmer: the ability to compile and run a simple application with no dependencies at all and without needing any IDEs or graphical tools.

👉 For this tutorial I'm using Linux, and we'll do everything in the console, without any graphical interfaces. This way, if you're accessing a server or using a very basic system, you'll still be able to write, compile, and run your applications without any problems.

Open a terminal:

👉 Windows: Win + R, type cmd or powershell.
👉 macOS: Cmd + Space, type Terminal.
👉 Linux: Ctrl + Alt + T (on most distributions).

Type the following commands to create a folder, enter the folder, and create your first C++ code file.

~$ mkdir project
~$ cd project
~$ vi main.cpp

vi is a console text editor, native to practically all Linux-based operating systems. Its usability is not very intuitive, so it's worth taking some time to learn how to use this tool — it can be extremely useful in many situations.

❗️ To start editing mode in vi, press the ‘a’ key.

#include "iostream"
int main()
{
    std::cout << "Hello World!" << std::endl;
    return 0;
}

❗️ When you’re finished editing, press the ‘Esc’ key to exit vi’s edit mode.
💡 To save and exit, type ':wq' and press ‘Enter’ (w → write, q → quit).

Back at the command prompt, with our code ready, let’s compile the application:

~$ g++ main.cpp

👉 After compilation, an executable file will be created with the default name a.out (we can specify any name we want).

Now your application is ready to run! 🎉

~$ ./a.out
Hello World!

All of this was very simple, but the tools we used are incredibly powerful!

If you spend some time mastering vi and gdb, you'll have an amazing trick up your sleeve.

Imagine how cool it is to be able to open any terminal and, in just minutes, have your own program running — like a hacker in an action movie! 💻