Special Printing Characters in C++

The C++ compiler recognizes some special characters for formatting. Table 3.2 shows the most common ones. You put these into your code by typing the backslash (called the escape character), followed by the character. Thus, to put a tab character into your code, you would enter a single quotation mark, the slash, the letter t, and then a closing single quotation mark:
char tabCharacter = `\t';
This example declares a char variable (tabCharacter) and initializes it with the character value \t, which is recognized as a tab. The special printing characters are used when printing either to the screen or to a file or other output device.

New Term: An escape character changes the meaning of the character that follows it. For example, normally the character n means the letter n, but when it is preceded by the escape character (\) it means new line.
Table 3.2. The Escape Characters.


What it means
\n new line
\t tab
\b backspace
\" double quote
\' single quote
\? question mark
\\ backslash
Special Printing Characters in C++ Reviewed by 1000sourcecodes on 20:57 Rating: 5
Powered by Blogger.