In this lesson you will learn how to create and read files.
There are two types of files: text files and binary files.
Text files have variable length records. (One line of text may have 20 characters, the next line 5, etc.) A text file must be read sequentially: line 1, line 2, etc. Text files are also called Sequential files.

Each record in a binary file must be exactly the same size. Because all of the records are the same length, a binary file can be read either sequentially or randomly. Suppose each record has exactly 20 bytes. The location of the first record in the file is always known. The second record begins 20 bytes (1 * 20) past that. The fifth record begins 80 bytes ( 4*20) past the beginning of the file. If the position where each record starts can be calculated, we can read the Nth record without reading all of the records before it. Binary files are also called Random Access files. Binary files are usually read in using a structure. They are discussed later.

Please study the material at each of the links below.

  1. Inches to Centimeters table
  2. Inches to Centimeters file
  3. Read a list of numbers with cin
  4. Read a list of numbers from file
  5. Read a list of people
  6. Read a list of people another way
  7. Read a list of people using getline
  8. Copy console to file
Like us on Facebook:

OER: Open Educational Resource
Creative Commons License Author: Janet E. Joy; Publisher:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
Creative Commons Attribution-NonCommercial 4.0 International License
Last modified: May 18 2017 14:04:45.