The backslash is a trigger. It says the next character is special. \n is  new line, \t is tab, \b is backspace. So logically, the backslash alone  can't be used to display a backslash, so you use \\ to display one  backslash. 
Backslash Commands 
When used in a character or string expression, the backslash character (\) is used to
give instructions to cout. For example, \n has the identical effect of endl. For example:
cout << “This is on one line.” << ‘\n’ << “This is on another line.”;
will produce the output
This is on one line.
This is on another line
The only advantage of \n is that it can be included in a string. For example:
cout << “This is on one line.\nThis is on another line.”;
will also produce the output
This is on one line.
This is on another line
 
No comments:
Post a Comment