Escape Sequences in C++
Escape Sequences:
Usually when we run a C++ program the compiler starts execution of the program and printing of output starts from the first column and first row of the screen. The columns are then increases by one according to the flow of the output and in this way when output occupies the entire first row the control is then automatically transferred to the second row to print the remaining output of the program and when the second row is completed then the control is transfered to the next row and in this manner the entire output is printed on the screen and there is no space in the output of the program but the entire output is concatenated with each other.
Thus Escape Sequences are the facility of programming languages that how to organize the output of a program in a best manner. Escape Sequences are used to organize the output of a program according to the user or the programmer's choice. Through Escape Sequences we can print the output of the program anywhere on the screen because by using escape sequences we can shift the control to the new line, transfer the control to one tab next column, or transfer the control to one space back from the current position etc. So escape sequences provide facility to display the output of the program according to the choice of the user or programmer. All escape sequences are usually used with the cout object of ostream class. Following are the list of escape sequences used in C/C++ programming languages:
Escape Sequences
|
Description
|
\a
|
It is used for alarm.
|
\b
|
It is used for backspace.
|
\n
|
It is used to transfer the control to new line.
|
\t
|
It is used to leave 8 spaces.
|
\r
|
It is used for carriage return.
|
\v
|
It is used for vertical tab.
|
\0
|
It is used for Null zero.
|
\\
|
It is used to print backslash.
|
\?
|
It is used to print question mark.
|
\’
|
It is used to print a single quote.
|
\”
|
It is used to print a double quote.
|
Program # 2
Write a C++ Program to display two messages on different
lines of the screen.
|
Program
#include<iostream.h>
main()
{
cout<<”Well Come”<<”\n”;
cout<<”Adalat Khan”;
getch();
}
|
This program will print " Well Come " on first row while " Adalat Khan " on second row of the screen.
0 comments:
Post a Comment