Chapter 3
Reading with Input Streams
IN THIS CHAPTER
Reading with the extraction operators
Dealing with the end of the file
Reading various data types
Reading data that is formatted with text
You have a file that you wrote to, but you need to read from it. After all, what good is a file if it’s just sitting on your hard drive collecting dust?
In this chapter, you learn how you can read from a file. This task begins by extracting the data. You can perform this task using extraction operators, just as you use insertion operators in the previous chapter.
Reading a file is tricky because you can run into some formatting issues. For example, you may have a line of text in a file with a sequence of 50 digits. You may not know whether those 50 digits correspond to 50 one-digit numbers, 25 two-digit numbers, or some other combination. When you create the file, you probably know its format, but the fun part is getting your C++ application to properly read from files you didn’t create. The file might contain 25 two-digit numbers, in which case you make sure that the C++ code doesn’t just ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access