< Previous | Contents | Next >

Displaying Variable Values

To display the value of a variable of one of the fundamental types, just send it to cout. Thats what I do next in the program. Note that I dont try to display shieldsUp because you dont normally display bool values.

Declaring and Initializing Variables 23


Tric k

image

In the first statement of this section I use what’s called an escape sequence—a pair of characters that begins with a backslash (\), which represents special printable characters.

cout << "\nscore: " << score << endl;

The escape sequence I used is \n, which represents a newline. When sent to cout as part of a string, it’s like pressing the Enter key in the console window. Another useful escape sequence is \t, which acts as a tab.

There are other escape sequences at your disposal. For a list of escape sequences, see Appendix E.

image