Week 5 - Strings and File I/O

Learning Objectives

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

  • Write programs that manipulate strings
  • Read and write text-based files
  • Format stream output
Quiz 2 is open this Thurs-Saturday. Covers weeks 3 and 4.

Midterm

The midterm can be taken this week or next.

Schedule

Day 1

Day 2

  • IO Formatting
  • File IO and Streams
  • Read Ch 4.10 and 13.1-13.4 (4.11 is a simpler version of 13.1-4 you can start with if you like)
  • String & Stream wrap-up (Ch 10.2.11-12)

Day 3

Day 4

  • No synchronous class meeting
  • Take midterm or start in on week 6 material
  • Review for and take quiz 2
  • Do assignment

Strings

Make sure you have done the strings material from the end of last week. Then read 5.14 and watch these videos.

There are a couple of tricky details when it comes to strings in C++. This video explains two important things to watch out for. Don't worry about memorizing every detail, of the difference between int and string::size_type focus on understanding the issue in play and how to use find() and length() correctly:

Tips and tricks for strings:

Do the CPP Lab String Basics.

As you are solving problems with strings, you may get an error that just tells you something like this:

terminate called after throwing an instance of std:: out_of_range...

Here is how you track down where exactly that error is coming from:

This video shows you how to use a loop to work your way through a string:

Do the CPP Lab String Loops.

I/O Formatting

Read Ch 4.10 on I/O formatting. This video explains the basics:

FileIO

Read Ch 13.1-13.4 on Reading Writing Files. These videos introduce file writing and reading:

And this one talks about the working directory - where your program will read and write files from:

You don't need them for the assignment, but I highly recommend you read 10.2.11 and 10.2.12. They talk about how to use strings as a stream (like a file you can read and write).

Midterm Review

Check in Elearn in the Files area for the Practice Midterm. Practice doing it with pen and paper - you will not be able to use VSCode for the midterm!