Escape Sequences
Certain special characters are represented as escape sequences. An escape sequence begins with a \ (backslash) followed by an alphanumeric character. For example, the \n escape sequence represents the newline character. Note that the two characters of an escape sequence are construed as a single character.
Escape Sequence |
Description |
\n |
Newline. Position the screen cursor to the beginning of the next line. |
\t |
Horizontal tab. Move the screen cursor to the next tab stop |
\r |
Carriage return. Position the screen cursor to the beginning of the current line. Do not advance to the next line. |
\a |
Alert. Sound the alarm bell. |
\\ |
Backslash. Used to print a backslash character. |
\' |
Single quote. Used to print a single quote character. |
\" |
Double quote. Used to print a double quote character. |
#include
<iostream>using
namespace std;int
main(){
cout <<
"A line of text using endl"<<endl;cout <<"A line of text using \n"<<"\n";
cout <<"fragment 1"<<"\t"<<"fragment 2"<<" using tab escape sequence"<<endl;
return 0;
}