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 Approaching
Recommended Schedule
Day 1
- Strings Continued
- CPPLabs: String basics
- Read Ch 5.14
- CPPLabs: String loops
Day 2
- 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-10.2.12
- Midterm Review
Day 4
- Review for and take quiz 2
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 CPPLab 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 CPPLab String Loops.
I/O Formating
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 Assignments area for the Practice Midterm. Check it out to make sure you both understand how the midterm works and to practice typing code in elearn you will not be able to use QTCreator for the midterm.
Wrapup
Take the quiz.
Do the assignment.