Entering the EOF Indicator

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.]


Image Portability Tip 5.1

The keystroke combinations for entering end-of-file are system dependent.



Image Portability Tip 5.2

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.104.149