Basic output in C++


Special characters

There are a variety of characters in C++ that are used for special purposes, such as single-quotes, double-quotes, backslashes, etc.

To include one of these as a "regular" character in an output stream, or to assign them as a character value, we have to let the compiler know that we don't want the "special" use of the character.

To do so, we use an escape sequence - which usually simply means preceding the desired character with a backslash \

Some of the common escape sequences are listed below:
Escape sequenceMeaning
\b backspace
\n newline
\t tab
\g bell
\\ backslash
\' single quote
\" double quote
\nnn use ASCII value
For example:

   cout << "Here comes a double-quote: \" there it went ... \n";

The ASCII value for a character is an integer interpretation of the bit pattern used to store the character.

For example, the ASCII values for the characters 'A' through 'Z' are 65 through 90.

Formatting output

Formatting output makes it clearer
The <iomanip> library contains formatting aids

Formatting real numbers

For real numbers we often want to specify both how wide the whole number is (std::setw works for this), and how many decimal places of accuracy are displayed.

The latter requires a two-step process: