CIS22A - Notes for Week 6, 10/28-10/31

Announcements and Reminders


Topics

Terminology

Chapter 5 - File I/O

Textbook Section 5.11

Some Background

  • What is a file?
  • Type of files: text and binary
  • Positioning in a file
Whatever you learned about cin and cout can now be applied to file streams.

Streams

  • ofstream
  • ifstream
  • fstream

Opening a file

  • via the open() function
  • via the constructor

Checking for a file open

Closing a file

Detecting EOF

Using type string to store a filename

How to read to the end of file

What happens if you read EOF?

Examples

   1. How would you write the numbers 1 - 100 in a file?
   2. How would you write the numbers 1 - 100 in a file in columns of 10?
   3. What is the average daily gain in the Dow Jones Industrial Average since the first of the year?
   4. What is the lowest and highest share price for Apple over the last 10 years?
   5. How do you copy a file?
   6. How many words are in Martin Luther King's I Have A Dream speech?
   7. How many times did Martin Luther King use the word, dream, in his I Have A Dream speech?
   8. Can you rewrite MLK's speech and make it I Have A Vision? (change all the dreams to visions)
   9. Encrypt a file by adding 5 to each character in the file.  So if the input file looks like this:

This is a nice
sample
input file.

then the output file would look like this:

Ymnx%nx%f%snhjxfruqjnsuzy%knqj3


Midterm Thursday

  • Covers chapters 1-5
  • Test is 48 minutes: 8:30 - 9:18
  • One pages of notes (8 1/2 x 11, both sides) allowed
How to study
  • Prepare one pages of notes
  • Review exercises 1-5
  • Start assignment 6
  • Work CodeLab exercises
text file
binary file

stream

ifstream

ofstream

fstream

open()

constructor

fail()

close()

EOF

parameterized manipulator
EOF
eof() function