Lesson 4: std::string — Text Made Easy
In C, text was char name[20] — a character array you managed by hand, watching the size and guarding against overflows. In C++ there's std::string: a text type that manages itself, grows on its own, and can be joined with +. In this lesson we'll learn one thing — basic std::string use: declare, prin
std::string is a smart 'text box': you put words in it, join with +, and ask .size() how many characters it holds — no managing a char array by hand.
- std::string
- C++'s self-managing text type. Comes from #include <string>. std::string s = "hi";
- string concatenation (+)
- You can join two strings with +: "Hello, " + name gives one combined string.
- .size()
- Returns the number of characters in the string. name.size() for "Ada" is 3.