In this article, we will discuss about Escape Sequence and their uses in C++ language with Examples and outputs.
“Escape sequences are special non-printing characters used to control the printing behaviour of output stream objects (eg “cout”).“
The compiler doesn’t show all these characters in the output.
Backslash (/) is called as an escape character.
Following are important escape sequences of C++ and we will further discuss them.
\n = newline
\r = carriage return
\t = tab
\” = double quote
\? = question
\\ = backslash
\’ = single quote
\n is used to print the code on a new line.
Use of \n
It inserts a new line and the cursor moves to the beginning of the next line.
Example of \n
In this example when we add /n in the cout the new line starts and other output is moved to next line.
\r Carriage Return
\r is used for return.
a carriage return is a type of escape character that will reset the position of the cursor to the beginning of a line of text
Example of Carriage Return
\t is used to insert tab space horizontally in the output of the code.
It usually gives the space of in word.
\” Double Quote
\” Backslash double quote is used to display ” ” quotes in the output
\’ Single Quote
\’ Backslash Single Quote is used to display ‘ ‘ Single quote in the output.
\? Backslash Question Mark is used to displaying the question mark in the output.
\\ Backslash Backslash is used to display the backslash in the output.