Zum Inhalt springen
KodeTrail

Camp 1 · Schritt 2 von 12

Hello, World!

Run C++ and understand streams — the << and >> style that defines its input and output.

12 Min.+50 XPAuf Englisch angezeigt — Übersetzung ist unterwegs

C++ prints differently from most languages, using streams. Odd at first, elegant once it clicks.

The program

C++Cloud-Run

Decoded

#include <iostream> — the input/output stream library, providing cout and cin.

std::cout — the "character output" stream (your screen). std:: is its namespace — the standard library lives under std:: to avoid name clashes.

<< — the stream insertion operator. Picture data flowing into the stream in the arrow's direction: cout << "Hello" pushes text out. Chain them: cout << a << b << c.

std::endl — ends the line (like \n) and flushes the output.

Reading input with cin

The mirror image uses >> and the cin stream:

int age;
std::cout << "Your age? ";
std::cin >> age;              // arrow points INTO the variable
std::cout << "Next year: " << age + 1 << std::endl;

The arrows tell the story: << pushes out to cout, >> pulls in to your variable from cin. Direction = data flow.

Checkpoint

In std::cout << "Hi"; which way does data flow?

Checkpoint

What is std:: in std::cout?

What's next

Variables and types — the core language, shared with C but with C++ comforts.