Sunday, April 21, 2024

Escape Sequence in c++:

 

A departure grouping contains an oblique punctuation line (\) image followed by one of the getaway succession characters or an octal or hexadecimal number. A hexadecimal break grouping contains a x followed by at least one hexadecimal digits (0-9, A-F, a-f).

Get away from groupings permit you to send nongraphic control characters to a presentation gadget. For instance, the ESC character (\033) is many times utilized as the main person of a control order for a terminal or printer. Some break successions are gadget explicit.

Character blends comprising of an oblique punctuation line (\) trailed by a letter or by a mix of digits are classified "get away from groupings." To address a newline character, single quote, or certain different characters in a person steady, you should utilize get away from successions. A departure succession is viewed as a solitary person and is in this manner legitimate as a person steady.


Get away from successions are normally used to determine activities, for example, carriage returns and tab developments on terminals and printers. They are additionally used to give exacting portrayals of nonprinting endlessly characters that generally have exceptional implications, for example, the twofold quote ("). The accompanying table records the ANSI get away from groupings and what they address.


Note that the question mark went before by an oblique punctuation line (\?) determines a strict question mark in situations where the person succession would be confounded as a trigraph. See Trigraphs for more data.


Escape Sequence:

Escape SequenceRepresents
 \aBell (alert)
 \bBackspace
 \fForm feed
 \nNew line
 \rCarriage return
 \tHorizontal tab
 \vVertical tab
 \'Single quotation mark
\"Double quotation mark
 \\Backslash
\?Literal question mark
 \ oooASCII character in octal notation
\x hhASCII character in hexadecimal notation
\x hhhh
Unicode character in hexadecimal notation if this escape sequence is used in a wide-character constant or a Unicode string literal.

For example, WCHAR f = L'\x4e00' or WCHAR b[] = L"The Chinese character for one is \x4e00".

Escape Sequence Characters:

\n:

‘n’ stands for a new line. It inserts a new line and the cursor moves from the beginning to the next line.

\t:

‘t’ stands for tab. It moves the cursor one horizontal tab from the current tab stop to the next tab stop. For example, an output statement is given below using escape sequence ‘\t’

Cout<<”Electronic\tClinic”;

The output of the statement will be as under:

Electronic     Clinic

‘\a’:

‘a’ stands for alarm. It causes a beep sound on the computer.

‘\b’:

‘b’ stands for backspace. It moves the cursor one space back. For example, a statement is given below using ‘\b’ escape sequence.

Cout<<”welcome\b”;

After execution of this statement, the string “welcome” will be printed and the cursor will move one space back. It means that it will be under the character ‘e’ of the word “welcome”. In the above statement if ‘\b’ is omitted, then the cursor will be at the end of the string. If another output statement is used after the above statement, then the printing will be started from character ‘e’ and ‘e’ will be deleted.

‘\r’:

‘r’ stands for return. It moves the cursor to the beginning of the current line.

‘\f’:

‘f’ stands for from feed. It caused the output to feed one paper on the printer attached to the computer.

\:

It is used to insert a backslash character in the output. For example, a statement is given below using ‘\’ escape sequence.

Cout<<”\Programming\”;

The output will be as under:

\Programming\

If s single backslash character is used, then there will be no effect on the output.

‘\’ :

It is used to insert a single quotation mark in the output. For example, a statement is given below using ‘\’ escape sequence.

Cout<<”\’welcom\’”;

The output will be as under:

‘welcome’

“ \” “:

It is used to insert a double quotation mark in the output. For example, a statement is given below using \” escape sequence.

Cout<<”\”welcome\””;

The output will be as under:

“welcome”

For example, write a program that displays the following output using an escape sequence:

C’          ‘L’            ‘i’           ‘n’           ‘i’           ‘c’

“Electronic”

click to learn c++ language in details on c++ programming language

No comments:

Post a Comment

last post

C language Vs C++ language in 2024

Popular Posts