File input

Published

2023-08-05

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

  1. We use a(n) ________________________________________________ object to read from files.
  2. True or false? We should never explicitly close our input file(s) when we’re done reading.
  3. A common practice is to use a(n) ______________ loop to iterate through our input file.
  4. Two ways of getting data from a file are the ____________________ function and the ___________________ operator.
  5. In a CSV file, a field is quoted if it contains ________________ as data.
  6. 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.

Original author: Clayton Cafiero < [given name] DOT [surname] AT uvm DOT edu >

No generative AI was used in producing this material. This was written the old-fashioned way.

All materials copyright © 2020–2023, The University of Vermont. All rights reserved.