Escape sequences are special characters used in control string to modify the format of an output. These specific characters are translated into another character or a sequence of characters that may be difficult to represent directly. For example, you want to put a line break in the output of a C++ statement then you will use “ ” character which is an escape sequence itself.

You are watching: The escape sequence moves the insertion point to the beginning of the next line.

This a guest article on surfacetoairnewyork.com

An escape sequence consists of two or more characters. For all sequences, the first character will be ”” i.e. backslash. The other characters determine the interpretation of escape sequence. For example, “n” of “ ” tells the cursor to move on the next line.

New Line ( ):

When a new line is necessary in the output, then this escape sequence is used. For example:

cout

First of all, “COMPUTER” is printed and” ” shifts the cursor to the next line. Then “SCIENCE” is printed on second line. A screenshot of output is shown below:


*
" data-medium-file="https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/1.png?fit=300%2C29&ssl=1" data-large-file="https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/1.png?fit=624%2C61&ssl=1" loading="lazy" class="size-full wp-image-1754" src="https://i1.wp.com/138.68.224.90/wp-content/uploads/2017/01/1.png?resize=624%2C61" alt="C++ New Line ( )" width="624" height="61" srcset="https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/1.png?w=624&ssl=1 624w, https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/1.png?resize=300%2C29&ssl=1 300w" sizes="(max-width: 624px) 100vw, 624px" data-recalc-dims="1" />C++ New Line ( )


Tab ( ):

A TAB is equal to eight spaces. Whenever TAB button is pressed from the keyboard, then 8 spaces are left blank. This escape sequence performs the functionality of TAB key in the output stream. The code given below will insert a TAB between two words.

cout


*
" data-medium-file="https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/2.png?fit=300%2C30&ssl=1" data-large-file="https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/2.png?fit=624%2C62&ssl=1" loading="lazy" class="size-full wp-image-1755" src="https://i2.wp.com/138.68.224.90/wp-content/uploads/2017/01/2.png?resize=624%2C62" alt="C++ Tab ( )" width="624" height="62" srcset="https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/2.png?w=624&ssl=1 624w, https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/2.png?resize=300%2C30&ssl=1 300w" sizes="(max-width: 624px) 100vw, 624px" data-recalc-dims="1" />C++ Tab ( )


As you can see after printing “COMPUTER”, 8 spaces are left blank and then “SCIENCE” is printed on the screen.

Alert Bell (a):

This escape sequence is used to play beep during execution. For example:

cout

First of all, “COMPUTER” is printed then a beep is played and after that “SCIENCE” is printed.

Backspace ():

Whenever we want to delete a single character, we press the button “backspace” from our keyboard. The same functionality can be achieved in C++ output with this escape sequence. For example:

cout


*
" data-medium-file="https://i2.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/3.png?fit=300%2C30&ssl=1" data-large-file="https://i2.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/3.png?fit=624%2C62&ssl=1" loading="lazy" class="size-full wp-image-1757" src="https://i2.wp.com/138.68.224.90/wp-content/uploads/2017/01/3.png?resize=624%2C62" alt="C++ Backspace ()" width="624" height="62" srcset="https://i2.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/3.png?w=624&ssl=1 624w, https://i2.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/3.png?resize=300%2C30&ssl=1 300w" sizes="(max-width: 624px) 100vw, 624px" data-recalc-dims="1" />C++ Backspace ()


First of all, “COMPUTER” is printed and after that “” comes which deletes the last character i.e. “R”. After that, “SCIENCE” is printed.

Single Quote (’):

To insert a single quote in the output, this escape sequence is used. Look at the code written below:

coutThis code prints single quotes at the start and end of the string.


*
" data-medium-file="https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/4.png?fit=300%2C30&ssl=1" data-large-file="https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/4.png?fit=624%2C62&ssl=1" loading="lazy" class="size-full wp-image-1758" src="https://i0.wp.com/138.68.224.90/wp-content/uploads/2017/01/4.png?resize=624%2C62" alt="C++ Double Quote (”)" width="624" height="62" srcset="https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/4.png?w=624&ssl=1 624w, https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/4.png?resize=300%2C30&ssl=1 300w" sizes="(max-width: 624px) 100vw, 624px" data-recalc-dims="1" />C++ Double Quote (”)


Carriage Return ( ):

This escape sequence moves the cursor at the beginning of current line. For example:

cout

First of all, “COMPUTER” is printed and after that “ ” comes which moves the cursor at the beginning of the line and “SCIENCE” is printed which overwrites the word written before.


*
" data-medium-file="https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/5.png?fit=300%2C30&ssl=1" data-large-file="https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/5.png?fit=624%2C62&ssl=1" loading="lazy" class="size-full wp-image-1759" src="https://i1.wp.com/138.68.224.90/wp-content/uploads/2017/01/5.png?resize=624%2C62" alt="Carriage Return ( )" width="624" height="62" srcset="https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/5.png?w=624&ssl=1 624w, https://i1.wp.com/surfacetoairnewyork.com/wp-content/uploads/2017/01/5.png?resize=300%2C30&ssl=1 300w" sizes="(max-width: 624px) 100vw, 624px" data-recalc-dims="1" />Carriage Return ( )


Form Feed (f)

This escape sequence is used in printing. It is used to insert a blank paper in the printed output. For example:

cout

After printing “COMPUTER”, the computer will include a blank paper and then print “SCIENCE”.

Conclusion

This article helped us understand some of the important escape sequences in C++. This is a kind of information a C++ beginner is expected to understand and know.

This is a guest post by Kamal Choudhary:

Kamal Choudhary is a tech geek who writes C++ programming tutorials on his blog. He is a student of computer science in the University of Gujrat, Pakistan. He loves to write about computer programming. You can find his full bio here. Follow him on twitter
ikamalchoudhary


*

About Rahil Shaikh Engineer. Blogger. Thinker. Loves programming and working with emerging tech. We can also talk on Football, Gaming, World Politics, Monetary Systems.

See more: Why Do My Tabs Close When I Click On Them, Tabs Closing Whenever I Click Them


Check These Out!


Get notified on our new articles


Subscribe to get the latest on Node.js, Angular, Blockchain and more. We never spam!
First Name:
Leave this field empty if you"re human:

11 comments


*

faheem
|October 8, 2017
6:08 pm
Reply

thanks bro it helped me in my first assignment please add more stuff and make and android app for this website


*

nimmi
|October 3, 2018
4:30 am
Reply

Can you explain the escape sequence to represent hexadecimal number and octal number with examples


*

Saba
|October 22, 2018
1:49 pm
Reply

Hexadecimal xHwOctal no On


*

Avinash Kumar
|October 21, 2019
5:42 am
Reply

Thanks for sharing this step by step information about C++ and read your complete post, you have explained in really very understanding method so keep posting such informative blog post.


Leave a Comment


Click here to cancel reply


Save my name, email, and website in this browser for the next time I comment.


Submit Comment
Get notified on our new articles
Subscribe to get the latest on Node.js, Angular, Blockchain and more
. We never spam!
First Name:
Leave this field empty if you"re human:
Blog
An Introduction to Microservices – Advantages, Challenges, Solutions
Highlight selected row in ngFor – Angular 2
0

*

Write for Uns . Terms & Condititop top . Privacy policy . Advertise .

surfacetoairnewyork.com © 2021


Subscribe to get the latest on Node.js, Angular, Blockchain and more. We never spam!
First Name:
Leave this field empty if you"re human:
surfacetoairnewyork.com | C++ for beginners: An Introduction to escape Sequences | surfacetoairnewyork.com
class="post-template-default single single-post postid-1752 single-format-standard samba_theme samba_left_nav samba_left_align samba_responsive cookies-not-set wpb-js-composer js-comp-ver-6.4.1 vc_responsive"
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok