...

/

Say “Hello!”

Say “Hello!”

Write and run your first C++ program using std::cout.

If you’ve ever wondered how video games, operating systems, or high-performance apps are built, C++ is behind many of them. This course gets you coding right away, no experience needed.

Welcome to C++! In this lesson, you’ll write and run your very first C++ program. No setup is required—just you, your keyboard, and a talking machine.

Press + to interact

Goal

You’ll aim to:

  • Write your first line of C++ code.

  • Use cout to print to the screen.

  • Understand how a basic C++ program is structured.

Your first C++ program

Let’s write your first C++ program below, which simply prints a greeting to the screen.

Press + to interact
C++
#include <iostream>
using namespace std;
int main() {
cout << "Hello, world!" << endl; // Prints the message and moves to a new line
return 0;
}

Note: Click the ‘‘Run’’ button to execute your code directly in the browser on the Educative platform. You don’t need to install any local setup—everything works conveniently right here!

Click the ‘‘AI Mentor’’ button to have our AI Mentor explain the code and help you understand it better.

That’s your first real C++ program.

What’s happening?

  • #include <iostream> lets you use input/output features.

  • using namespace std; lets you use keywords like cout and endl without writing cout or endl.

  • int main() is the starting point of every C++ program.

  • cout << prints text to the console.

  • << endl adds a line break.

  • return 0; means the program ended successfully.

Press + to interact
Structure of a C++ program
Structure of a C++ program

Try this

Change the message!

cout << "I'm learning C++!" << endl;

 Anything in quotes gets printed.

Mini challenge

Add two more lines:

cout << "Welcome to the machine." << end
cout << "Let's write some code!" << endl;
Press + to interact
C++
#include <iostream>
using namespace std;
int main() {
// Make changes in the code below
cout << "Hello, world!" << endl;
return 0;
}

If you’re stuck, click the ‘‘Show Solution’’ button.

 You've created a conversation.

What’s next?

In the next lesson, we’ll turn C++ into your calculator—and do real math with code!