Strings — Working with Text
← Course home · ← Arrays module · Unit 11/16 · Syllabus
You’ve handled text at the edges — getline, the mixing trap, one string method in a challenge. This unit puts text at the centre: the two ways C++ holds it, the std::string toolkit in full, and character-by-character processing — the foundation for every analyzer, validator, and parser to come.
In this module you will learn
- the conceptual difference between character arrays (C-strings) and
std::string— and why the course standardizes onstd::string - creation, input (
>>vsgetline),length, indexing, concatenation, comparison - searching (
find+npos) and substring (substr+ the length-not-index rule) - modification: insert, erase, replace
- character processing with
<cctype>: classify and convert chars - conversion basics (string ↔ number), and the common mistakes gallery
Module map
| Page | What’s inside |
|---|---|
| Lesson 1 — Two ways to hold text | chars, character arrays, std::string, creation, input, getline |
| Lesson 2 — Measuring, indexing, joining, comparing | length, indexing + traversal, concatenation, comparison |
| Lesson 3 — Finding, cutting, changing | find + npos, substr, insert/erase/replace, <cctype> processing |
| Lesson 4 — Conversions and mistakes | string↔number conversion, the common mistakes gallery |
| Exercises | 26 exercises with separated solutions (S1–S26) |
| Debugging | 10 seeded string bugs |
| Predictions | 10 output/trace problems, answers separated |
| Challenges | 10 challenges with separated solutions |
| Labs | 7 text labs, each with solution + explanation |
| Mini-project | The Text Analysis Toolkit |
Try it yourself first
Same rule as every module: attempt 15 minutes before opening any solution. Strings add one habit to the pre-code routine: write out the boxes — a string is a row of chars with a length, and drawing "cat" as c·a·t with indices 0, 1, 2 turns most off-by-one and boundary bugs into things you can see.
Pacing
Unit 11 spans one week (2 sessions):
- Session 11.1 — Lessons 1–2 + Ex 1–13 · Lab 1 or 2
- Session 11.2 — Lessons 3–4 + Ex 14–26 · one analysis lab + the mini-project
What comes next
The Files module applies this entire toolkit to files — reading and writing lines is getline at scale. And the password/validator labs here are the direct ancestors of input-handling in every later project.
Checklist
- I can explain what a character array is, what a
std::stringis, and why the course usesstd::string - I can create, read (
>>andgetline), measure, index, and traverse strings - I can concatenate and compare strings — and know the comparison rules
- I can search with
find/nposand extract withsubstr(length, not index!) - I can modify strings with insert/erase/replace
- I can classify and convert characters with
<cctype> - I can convert between strings and numbers — and know the common string mistakes