- 01Getting Started
- 02Your First Output (cout)
- 03Variables and Types (int/double/string/bool)
- 04Conditionals (if statements)
- 05Loops (for statements)
- 06Writing a Function
- 07Working with Arrays
- 08Loops (while statements)
- 09Pointer Basics
- 10References
- 11Classes (Object-Oriented Programming)
- 12Constructors and Destructors
- 13Inheritance
- 14Using vector (the Standard Library)
- 15String Manipulation (string)
- 16Structs (struct)
- 17Error Handling (try/catch)
- 18The Ternary Operator
- 19The switch Statement
- 20[Applied] Build a Mini Inventory Management System
String Manipulation (string)
This lesson covers basic string manipulation using std::string. It's for anyone searching "C++ string manipulation."
std::string comes with handy features โ length() to get the length, substr() to extract a substring, and the + operator to concatenate strings.
The example checks the character count with message.length(), and extracts the first 5 characters with message.substr(0, 5).
A common early mistake is how character counting works with multi-byte characters. std::string's length() returns a byte count, so a single non-ASCII character can be counted as multiple bytes.
In real projects, string manipulation โ validating user input, formatting a log line, and more โ is essential to nearly every program.
๐งช This site can't compile or run C++ directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
