< Previous | Contents | Next >
To display the value of a variable of one of the fundamental types, just send it to cout. That’s what I do next in the program. Note that I don’t try to display shieldsUp because you don’t normally display bool values.
Declaring and Initializing Variables 23
Tric k
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.