Writing your first C++ program: where to start and how to make sense of it

๎€ฃ

September 16 2026

Stepping into programming can feel like diving into deep water, and yet C++ remains one of the most formative languages for really understanding what a computer does when we ask it for something. It is not the friendliest starting point for anyone used to graphical interfaces, but it is probably the language that forces you to think more than any other, and that makes it an excellent place to begin.

Your first C++ program does not need to be complicated. The ideal is to start with something that runs, that prints a simple sentence on screen and gives you that small satisfaction of watching your first piece of code turn into action. Everything grows from there.

What C++ is, and why use it in 2026?

C++ appeared in the early 1980s as an extension of C, with an object-oriented approach. Today, in 2026, it is still used in game development, system software, embedded applications, industrial simulators and even high performance finance. It is fast, flexible and, above all, it teaches you to write code that has been thought through.

In a period when it is easy to write code that simply works, thanks to libraries and frameworks that do everything for you, C++ asks you to stop and consider. It wants you to declare what you are using, how and why. As training, that is an enormous advantage.

Writing something: the classic “Hello, world”

The first thing to do is install a compiler. There are several: GCC, clang, or a full development environment such as Visual Studio, Code::Blocks, or simply VS Code with the C++ plugin.

Then you are off.

#include <iostream>

int main() {
    std::cout << "Hello, world!" << std::endl;
    return 0;
}

This is your first C++ program. Let us go through it line by line, without too much jargon.

  • #include <iostream> tells the compiler that you want to use a library for printing to the screen.
  • int main() is the main function: this is where everything starts.
  • std::cout is the command for writing to the screen.
  • return 0; closes the program and tells the system that all went well.

You compile, you run, and there is your message appearing in the console. Simple and powerful at the same time.

Talking to the user: input and output

Now that you know how to print something, it is time to ask for something in return. Basic interaction with the user goes through the keyboard. Here is a small example.

#include <iostream>
#include <string>

int main() {
    std::string name;
    std::cout << "What is your name? ";
    std::getline(std::cin, name);
    std::cout << "Nice to meet you, " << name << "!" << std::endl;
    return 0;
}

With std::getline(std::cin, name) you let the user type their name, spaces included. Then you print it inside the reply. Three lines and you have already built an interaction. That is all there is to it: the user feels acknowledged, and you begin to understand the basic input-output cycle.

Variables and operations

One step further: doing something with data. You can ask for two numbers and add them together, like this:

#include <iostream>

int main() {
    int a, b;
    std::cout << "Enter two numbers: ";
    std::cin >> a >> b;
    int sum = a + b;
    std::cout << "The sum is: " << sum << std::endl;
    return 0;
}

This time we used std::cin to read two whole numbers. The sum is stored in a variable and then shown on screen. This is how you start handling data, which is the heart of programming.

Controlling the flow: conditions

Programs do not always do the same thing. Sometimes they have to react to whatever the user types. Conditional statements let you do that.

if (name.empty()) {
    std::cout << "You did not enter a name." << std::endl;
} else {
    std::cout << "Welcome, " << name << "!" << std::endl;
}

With this simple if block, the program checks whether the name is empty and reacts accordingly. You can imagine how useful this becomes in larger contexts, when you have to validate data, handle errors or adapt to different situations.

Loops: repeating an action

If you want to repeat an operation several times, printing the numbers from 1 to 5 for instance, you can use a for loop:

for (int i = 1; i <= 5; ++i) {
    std::cout << "Number: " << i << std::endl;
}

Or, when you do not know in advance how many times you will need to repeat something, you can use a while loop:

int x = 0;
while (x < 3) {
    std::cout << "Value of x: " << x << std::endl;
    x++;
}

These are the basics of flow control. Once you have them under your fingers, you can build any kind of iterative program.

Your own functions

C++ allows, and in fact encourages, splitting code into reusable functions. For example:

void greetUser(std::string name) {
    std::cout << "Hello, " << name << "!" << std::endl;
}

And then you use it like this inside main():

greetUser("Anna");

This approach keeps your code tidy, readable and easier to manage, especially once programs start to grow.

Towards object-oriented programming

One of the strengths of C++ is OOP (Object-Oriented Programming). It may look like a distant concept at first, but sooner or later you will get there. In C++ you can create classes, containers that combine data with the functions acting on that data.

Here is the simplest possible example:

class Person {
public:
    std::string name;

    void greet() {
        std::cout << "Hello, I am " << name << "!" << std::endl;
    }
};

And then in main():

Person p;
p.name = "Marco";
p.greet();

Understanding classes will lead you to better structured programs that are easier to change over time.

Learning by getting it wrong: the best method

Writing code means, very often, getting it wrong. The compiler will warn you with mysterious messages, sometimes endless ones, sometimes apparently useless ones. Do not let it discourage you. Every error is a step forward. A forgotten bracket, an undeclared variable, a typo: all of it is part of learning.

The best advice is simple: try things. Do not settle for copying and pasting examples. Write them from scratch. Change them. Alter the numbers, the strings, the variable names. Watch what happens. Learn by observing.

Practice: the real engine of learning

Once you have written your first basic programs, you can try something a little more concrete:

  • A program that converts Celsius into Fahrenheit
  • A small multiple choice quiz
  • A command line calculator
  • A euro/dollar converter

Every exercise, even the most ordinary one, will teach you something new: how to handle input, how to format output, how to run a check, how to simplify your code.

Your first C++ program is the beginning of a path that can take you a long way. However strict this language is, it hands you the tools to build solid, efficient, customisable applications.

Even in 2026, with artificial intelligence and automation spreading everywhere, C++ keeps its value. Precisely because it obliges you to understand what you are doing, it genuinely trains you. It does not let you believe you are a programmer: it turns you into one.

Take the time to learn the fundamentals properly. Write plenty of code. Experiment. And above all, enjoy watching an idea turn into something that works.

The best part of programming starts exactly there.


Our courses: https://itamde.com/en/online-courses/

โ–ผ FOLLOW US โ–ผ
ยป Facebook: https://www.facebook.com/itamde
ยป Instagram: https://www.instagram.com/itamdestudio
ยป X (Twitter): https://x.com/itamdestudio
ยป SUBSCRIBE TO OUR CHANNEL: https://www.youtube.com/channel/UCZ4dhshzpVbbRPVuL9TNH4Q

Recent Posts

Recent Comments

"

Itamde is also an online programming school.

Itamde

Learn what you want, at your own pace

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

You may also be interested in...

Javascript

Introduction to jQuery and how it simplifies JavaScript

When you start writing JavaScript, one of the first things you feel is that you are surrounded by lines, by functions and sometimes by far too many semicolons. You find yourself writing and rewriting similar things, like reaching for an HTML element or responding to a...

Stay up to date with the latest news and developments

Access restricted content

Discover behind-the-scenes details of our projects, exclusive resources, and the progress of our creations in real time.

Sign up for our newsletter

Receive our news, creative insights, and updates from the studio directly in your inbox.

Follow us

Join our community on social media to follow our daily projects and interact with us.