On OS X/Linux/UNIX systems and many others, end-of-file is entered by typing
<Ctrl> d
on a line by itself. This notation means to press and hold down the Ctrl key, then press the d key. On other systems such as Microsoft Windows, end-of-file can be entered by typing
<Ctrl> z
[Note: In some cases, you must press Enter after the preceding key sequence. Also, the characters ^Z
sometimes appear on the screen to represent end-of-file, as shown in Fig. 5.11.]
Portability Tip 5.1
The keystroke combinations for entering end-of-file are system dependent.
Testing for the symbolic constant EOF rather than –1 makes programs more portable. The C standard, from which C++ adopts the definition of EOF, states that EOF is a negative integral value, so EOF could have different values on different systems.
In this program, the user enters grades at the keyboard. When the user presses the Enter (or the Return) key, the characters are read by the cin.get()
function, one character at a time. If the character entered is not end-of-file, the flow of control enters the switch
statement (Fig. 5.10, lines 60–96), which increments the appropriate letter-grade counter.
13.58.44.229