String Operations: concat substr find replace
Concatenate, slice, search, and replace string content with the std::string API.
Concatenation with +
The + operator joins two strings into a new one. += appends in place.
std::string a = "Hello, ";
std::string b = "World";
std::string c = a + b; // "Hello, World"
a += b; // a is now "Hello, World"Appending Efficiently
Repeated + on long strings creates many temporaries. Use += or append() for hot loops.
std::string result;
for (auto& word : words) {
result += word;
result += ' ';
}All lessons in this course
- std::string vs C-Style Char Arrays
- String Operations: concat substr find replace
- String Stream stringstream for Parsing
- String Conversions: to_string and stoi