Skip to content

Exercise 1 of 10 · Output

Hello, Out Loud

What you will make

A banner with your own name inside it, printed by a C++ program you compiled and ran yourself.

The one new idea: std::cout sends text to the screen

Almost every program you write from here on will show you something. std::cout is how a C++ program talks back to you — and how you check whether it did what you thought it would.

Go straight to the code ↓

Compiled, then run

C++ is a compiled language, and that changes the shape of "running" a program. Python and JavaScript read your code and act on it line by line. C++ does not. A program called a compiler reads the entire file first, turns it into a small standalone piece of machine code, and only then does anything run at all. Press Run here and both steps happen for you, one after the other, before a single character reaches the screen.

Two lines are doing work before main even starts:

  • #include <iostream> pulls in the part of the C++ library that knows how to print and read text. iostream is short for input/output stream, and without this line the compiler has never heard of std::cout at all.
  • int main() { ... } marks the one function every C++ program must have. When your program starts, this is where it starts — the lines between the braces run top to bottom, in order.

What std::cout does

Whatever sits to the right of << after std::cout gets shown on the screen. Wrap it in double quotes and the compiler treats it as plain text, printed exactly as written — letters, spaces, punctuation and all.

C++
std::cout << "the exact words" << std::endl;

Three parts are doing three different jobs:

  • std::cout is the output stream itself — think of it as the screen, addressed by name. The std:: in front means "look inside the standard library for something called cout," which is where iostream put it.
  • << is the insertion operator. Read it as an arrow: it points the text on its right into the stream on its left.
  • std::endl ends the line, the way pressing Enter would, and immediately shows everything printed so far.

A worked example

A different program, so the one in the editor stays yours to finish:

C++
#include <iostream>

int main() {
    std::cout << "--> ready" << std::endl;
    std::cout << "--> steady" << std::endl;
    std::cout << "--> go" << std::endl;
}

Running that prints three lines:

Output
--> ready
--> steady
--> go

Three std::cout lines, three lines of output, in the order they were written. The arrows and the spaces come out exactly as typed — the compiler did not tidy anything up or add anything of its own. Notice, too, that main here has no return statement. C++ makes a single exception for main: reaching its closing brace without one is the same as writing return 0;, so a program that finishes normally needs nothing extra at the bottom.

Your turn

The editor already holds a working program. It prints a banner: a row of = signs, two lines of text, then another row of = signs.

One thing is missing. The second line says YOUR NAME instead of your name.

Replace those two words with your own name, keep the quotes exactly where they are, and press Run.

That is the entire task. You are not expected to write a line from scratch yet.

If something goes wrong

Press Run and you may see a red panel instead of a banner — that is the compiler, not your program, and it means the build stopped before anything could run. Read the first line of it; C++ compiler messages are verbose, but the first error is almost always the real one.

If it complains about your name, it is almost always the quotes. The text you want printed has to sit between them — "Hello, Leo!" works, Hello, Leo! on its own does not, because without quotes the compiler reads your name as an identifier it has never declared, not as words to print.

Nothing you do here can break anything. Change it, run it, change it again — a fresh compile is a few seconds away.

Write your code

Runs in your browser. Press Run (or Ctrl/Cmd+Enter) and the output is checked for you.

Ctrl/Cmd+Enter to run

Press Esc then Tab to move keyboard focus out of the code editor.

Ready
Output will appear here after you run your code.

The runtime is starting in the background. You can type now — it will be ready before you are.

The answer appears here once you have run your code at least once.

Things that often go wrong here

Deleting the quotes along with the placeholder
Without quotes, the compiler reads your name as code rather than text — a bare word it has never heard of — and refuses to build the program at all, pointing at the first name it does not recognise.
Changing the wrong line
Only the second std::cout line has a placeholder. The rows of = signs are the top and bottom of the banner, written in #include <iostream>'s own std::cout calls, and stay exactly as they are.
Using single quotes instead of double quotes
In C++ single quotes are for one character only. 'Hello, Leo!' is not one character, so the compiler stops before your program ever runs, rather than printing something odd. Double quotes are what make a run of text.

Want a blank editor instead? Open the C++ playground.