File input
For your projects you’ll need to be able to read data from a file. Here’s a primer on reading data from plain text and CSV files, including CSV values with quoted fields.
Resources
Additional reading
Comprehension check
- We use a(n) ________________________________________________ object to read from files.
- True or false? We should never explicitly close our input file(s) when we’re done reading.
- A common practice is to use a(n) ______________ loop to iterate through our input file.
- Two ways of getting data from a file are the ____________________ function and the ___________________ operator.
- In a CSV file, a field is quoted if it contains ________________ as data.
- The
istream::peek()
method will read a character but will not ___________________ it.
Answers: ʇɔɐɹʇxǝ / sɐɯɯoɔ / >> uoᴉʇɔɐɹʇxǝ ’()ǝuᴉlʇǝƃ::pʇs / ǝlᴉɥʍ / ǝslɐɟ / ɯɐǝɹʇsɟᴉ::pʇs
Another example
Here’s another example of file input, in case you find it helpful.
Copyright © 2023–2025 Clayton Cafiero
No generative AI was used in producing this material. This was written the old-fashioned way.