Escape Sequences in C++

The following table lists the commonly used escape characters in C++:

Escape SequenceName

Description

\\

Backslash

Inserts a backslash character.

\’

Single quote

Displays a single quotation mark.

\”

Double quote

Displays double quotation marks.

\?

Question mark

Displays a question mark.

\a

Alert (bell)

Generates a bell sound in the C++ program.

\b

Backspace

Moves the cursor one place backward.

\f

Form feed

Moves the cursor to the start of the next logical page.

\n

New line

Moves the cursor to the start of the next line.

\r

Carriage return

Moves the cursor to the start of the current line.

\t

Horizontal tab

Inserts some whitespace to the left of the cursor and moves the cursor accordingly.

\v

Vertical tab

Inserts vertical space.

\0

Null character

Represents the NULL character.

\ooo

Octal number

Represents an octal number.

\xhh

Hexadecimal number

Represents a hexadecimal number.

Note: The output of some of these escape sequences depends upon the compiler you are working on.

C++ Escape Sequences

Escape sequences in C++ are characters or sequences of characters that can be used inside a string literal to represent some special characters. They are prefixed with a backslash \ and are used to represent characters such as new line, carriage return, etc. that cannot be represented normally.

In this article, we will learn about escape characters in C++ and how to use them in our C++ program.

Similar Reads

Escape Sequences in C++

The following table lists the commonly used escape characters in C++:...

Examples of Escape Characters in C++

The following examples demonstrates the use of above escape sequences in C++:...

Conclusion

These sequences allow you to represent characters that cannot be directly typed, such as newlines, tabs, and backslashes. Knowing how to use escape sequences enhances your ability to handle text and improves the readability and functionality of your code....