Loops and Text Input
Now that you've seen how loops work, let's look at one of the most common and important tasks assigned to loops: reading text character-by-character from a file or from the keyboard. For example, you might want to write a program that counts the number of characters, lines, and words in the input. Traditionally, C++, like C, uses the while loop for this sort of task. We'll investigate now how that is done. If you already know C, don't skim through this part too fast. Although the C++ while loop is the same as C's, C++'s I/O facilities are different. This can give the C++ loop a somewhat different look. In fact, the cin object supports three distinct modes of single-character input, each with a different user interface. Look ...
Get The Waite Group's C++ Primer Plus, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.