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
Midterm
Recommended Schedule
Day 1
- Strings Continued
- CPP Lab String basics
- CPP Lab String loops
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)
Day 3
- String & Stream wrap-up (Ch 10.2.11-12)
- Midterm Review
- Check out assignment
Day 4
- 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 is next week! 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!