Escape Sequences in C++ language

Escape Sequences in C++ language

Escape Sequences:

In the C++ language, escape sequences are special characters that used to format the strings. These characters do not display as an output. These characters used with backslash ‘\’ that call escape character. List of the Escape sequences that used in the C++ language are:

 

Escape SequencesUsed for
\nNext line
\tHorizontal tab
\aAlert
\bBackspace
\0Null character
\\Backslash
\’Single quote
\”Double quote
\vVertical tab
\fForm feed
\rCarriage return

Now we describe the detail of each escape sequence one by one.

  • \n:

‘\n’ escape sequence used to break the current line or go to the next line. For example:

cout<<“Hello\nMyFSTech”;

Firstly, Hello will print then through ‘\n’ cursor will go to the next line. At last MyFSTech will print.

  • \t:

‘\t’ escape sequence used to insert TAB in the output. For example:

cout<<“Hello\tMyFSTech”;

In this case, Hello will print than ‘\t’ put TAB space. At last MyFSTech will print.

  • \a:

‘\a’ escape sequence used to play beep during the execution. For example:

cout<<“Hello\aMyFSTech”;

In this case, Hello will print than due to ‘\a’ the beep will play. At last MyFSTech will print.

  • \b:

‘\b’ escape sequence used to insert backspace in the output. For example:

cout<<“Hello\bMyFSTech”;

Here, Hello will print than due to ‘\b’ o will remove of ‘Hello’. At last MyFSTech will print. So the output will ‘Hellworld’.

  • \f:

‘\n’ escape sequence used in printing. It insert a blank paper in the output. For example:

cout<<“Hello\fMyFSTech”;

In this case, Hello will print than blank paper will insert and finally, MyFSTech will print.

  • \r:

‘\n’ escape sequence used to remove all text on the output screen and take curser at the start of the line. For example:

cout<<“Hello\rMyFSTech”;

In this case, Hello will print than due to ‘\r’ Hello will remove and MyFSTech will print. So the output will ‘MyFSTech’.

  • \’:

‘\” escape sequence used to insert a single quote in the output. For example:

cout<<“\’Hello MyFSTech\'”;

In this case, Hello MyFSTech will display in the single quotes.

Program:

#include<iostream.h>

using namespace std;

void main(){

cout<<“this\bThis\t article is \n best for \”beginners\””;

return 0;

}

output:

This           article is

best for “beginners”

 

We have the collection of other topics of the C++ course and technology updates.

Also, like our facebook page

Summary
Review Date
Reviewed Item
Escape Sequences in C++ language
Author Rating
51star1star1star1star1star

Add a Comment

Your email address will not be published. Required fields are marked *