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. See discussion board for details.

Day 1

Day 2

Day 3

  • Optional - String & Stream wrap-up (Ch 10.2.11-12)
  • Midterm Review
  • Check out assignment

Day 4

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

Online Activity Outline

Quiz 2 opens Thursday—it focuses on the material from weeks 3 & 4 (Ch 4.1-4.7 and Ch5), but concepts from the first weeks are likely to be needed (variables, conditionals, etc...). Use the book author's website to do some practice quiz questions as you work on the new material.

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

Midterm can be taken this week or next. Check the discussion board for details.

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!

If you are planning on taking the midterm next week, you should start in on the first day of week 6 this week. Saving all of week 6 and the midterm to next week will make for an awful week 6.