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
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
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
What is the escape character \t used for?
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!"
To output a quotation mark inside a string, you write \" instead of just ".
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
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 →