Week 4 - Strings
Learning Objectives
Upon finishing this learning module, you should be able to:
- Write programs that manipulate strings
- Use the
char
data type and understand how it relates toint
- Navigate directories and compile files from the command line
Schedule your Midterm
Recommended Schedule
Day 1
- Chars
- CPP Lab Characters
- String Basics
Day 2
- Working With Strings
- String Practice worksheet
- CPP Lab String basics
Day 3
- String Problem Solving
- String Loops
- CPP Lab String loops
Day 4
Chars
Read Ch 4.3-4.7. This video explains a bit about chars:
Do Characters CPP Lab .
String Basics
Read Ch 4.8: This video covers the basics:
Working With Strings
Read 10.2 (you can stop at 10.2.10). This video introduces the basics:
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:
Start String Basics CPP Lab .
String Problem Solving
This video has more detailed examples of using functions like find()
and length()
to solve problems involving strings:
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:
Start String Basics CPP Lab .
String Loops
This video shows you how to use a loop to work your way through a string either chunk by chunk or character by character:
Ch 5.14 has another interesting example of looping through the characters in a string.
Do the CPP Lab String Loops.
Working on the Command Line
Before there were windows and mice, the way we interacted with computers was all based on text input into consoles (like the programs we are currently writing). Many tools programmers use work on the command line (behind the scenes, VSCode is using text-based commands to call the compiler) - learning to use the command line is essential.
In parallel with the assignment, do the following activities to start getting familiar with the command line.
These videos demonstrate the basics:
This Command Line Guide provides detailed instructions for how to open a command prompt, set up the path, navigate, and use g++.
For a more detailed treatment read either this Windows command line guide (up to 2.6). or this Mac/Linux command line guide (up to 3.5).