Strings

Lesson 9 of 20

std::string is text with superpowers: glue words with +, count with length() and walk characters by index.

The big picture

Text as a first-class type

std::string handles its own memory: text can grow, shrink, join and compare — no manual bookkeeping.

std::string

The C++ text type — bring it in with #include <string> and it manages itself.

+ glues text

"foot" + "ball" makes "football" — spaces are characters too.

.length()

Counts the characters: "Ada".length() is 3.

Indexing

s[0] is the first character; the last is s[s.length() - 1].

Compare with ==

Two strings are equal only if every character matches, in order.