Week 7 - Advanced IO

Learning Objectives

Upon finishing this learning module, you should be able to:

  • Read and write text-based files
  • Format stream output
  • Use exception handling for error management

Schedule

Day 1

In class:

  • Formatting
  • File Reading

Outside class:


Day 2

  • Veteran's Day holiday

Day 3

In class:

  • More Stream IO

Outside class:


Day 4

In class:

  • Exceptions

Outside class:



File IO and Streams

Read Ch 11 on File IO and Streams.

These optional videos reinforce the concepts from the reading:

Basic File Reading (11.5-11.6)


Using eof to read a full file (11.7)


Deciding on getline vs >> (11.8)


Using Stringstreams (11.10)


Working Directory

The working directory controls where your program will read and write files from. It is NOT always the same as the directory your program is in! Learn more about it in this video:

As the video explains, if your data file is in the same folder as your program, and you run the program from inside that folder, you should not need to worry about doing anything special. It only becomes an issue when your program is in one folder and your data file is in another.


Exception Handling

Read the second half of Ch 10 on Exception Handling (10.6-10.11).