Escape Sequences in C++
The following table lists the commonly used escape characters in C++:
Escape Sequence | Name | 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.