Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Output · Lesson 14 of 25

std::cout

A free lesson from Swipe Coding · C++, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Time to make C++ actually say something on screen. 🔊

To display text on the screen (the "console") in C++, you use std::cout together with the << ("insertion") operator. Whatever you put after << gets sent to the console. To use it, your file needs #include <iostream> at the top — that line pulls in the standard input/output library.

#include <iostream>

int main() {
    std::cout << "Hello, C++!" << std::endl;
    return 0;
}
A complete, runnable C++ program. It prints exactly one line: Hello, C++!
Quick check

What does this program print when you run it?

#include <iostream>

int main() {
    std::cout << "Hello, C++!" << std::endl;
    return 0;
}
🤖
That little std::endl does two jobs at once. 📏

std::endl inserts a newline, just like pressing Enter, so the next output starts on a fresh line below it. It also does something extra: it "flushes" the output buffer, forcing any pending text to actually appear on screen right away. Most of the time you can also use the escape sequence "\n" instead — it inserts the same newline character, but without forcing a flush.

std::cout << "First line" << std::endl;
std::cout << "Second line\n";

// Output:
// First line
// Second line
Both lines end up on their own row — std::endl and "\n" both start a new line for whatever comes next.
Fill in the blank

The stream manipulator ____ inserts a newline and also forces the output buffer to flush immediately.

🤖
That std:: prefix is just an address label, nothing scary. 📬

std:: means "this comes from the std namespace" — the part of C++'s standard library where things like cout and endl live. You will sometimes see files that start with using namespace std; so they can write cout instead of std::cout everywhere. This course writes std:: explicitly, since it makes it obvious exactly where each name comes from.

True or false

You must write using namespace std; before you are allowed to use std::cout.

🤖
Next up: making stubborn characters like quotes and tabs behave. ⌨️

You now know how to print plain text with std::cout. Next, you will learn about escape characters — special codes that let you insert things like line breaks, tabs, and quotation marks directly inside a piece of text.

Keep your streak going in Swipe Coding

Swipe through every level of C++ on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →