0Pricing
C++ Academy · Lesson

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

  1. std::string vs C-Style Char Arrays
  2. String Operations: concat substr find replace
  3. String Stream stringstream for Parsing
  4. String Conversions: to_string and stoi
← Back to C++ Academy