Writing to, and reading from, files is a common task for software developers. The following videos will show you how.
Before reading in from a file, you'll need to know about the getline() function.
Now, let's read the file!
Review Questions
The following are examples of questions similar to what you can expect to see on the next exam.
- How would you open a file called "data.txt" for reading (using "ifs" as the file stream variable)? ifs.open("data.txt");
- How would you close it? ifs.close();
Above and Beyond
The content past here is related, but beyond the scope of the class. In other words, you will not be tested on this!
Generalizing an Output Function
Sometimes you want to output files to multiple places, this video will show you a little trick to doing so.