Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Output · Lesson 15 of 25

Escape Characters

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

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

🤖
Some characters need a little help to show up in your text. 🔡

Sometimes you want to output something that cannot simply be typed as-is inside a string — for example a line break in the middle of a sentence, or a quotation mark. For this, C++ has "escape characters": a backslash (\) followed by a letter that has a special meaning.

std::cout << "First line\nSecond line" << std::endl;

// Output:
// First line
// Second line
\n produces a line break — right in the middle of a single string.
Fill in the blank

The escape character ____ produces a line break in the middle of a string.

The escape character \t produces a tab — a larger, even amount of spacing. This lets you roughly align text into columns.

std::cout << "Name:\tMax" << std::endl;
std::cout << "Age:\t17" << std::endl;

// Output:
// Name:   Max
// Age:    17
\t makes sure "Max" and "17" line up roughly underneath each other, even though "Name:" and "Age:" have different lengths.
Quick check

What is the escape character \t used for?

🤖
This trick lets a quotation mark live peacefully inside a string. 💬

If you want to output a regular quotation mark in the middle of a string, there is a problem: C++ would think the string ends there. The solution is \" — an "escaped" quotation mark that is treated as plain text instead of the end of the string.

std::cout << "She said: \"C++ is powerful!\"" << std::endl;

// Output:
// She said: "C++ is powerful!"
Without the backslash before the quotation marks, the string would end too early and the code would fail to compile.
True or false

To output a quotation mark inside a string, you write \" instead of just ".

🤖
Even the backslash needs its own special trick to print itself. ⚙️

And what if you want to output a backslash itself — for example in a file path? Since a single backslash normally starts an escape sequence, you have to double it: \\.

std::cout << "The path is: C:\\Users\\Ada" << std::endl;

// Output:
// The path is: C:\Users\Ada
Each \\ in the code produces exactly one single backslash in the output.

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 →