C++20 sections · 1024 units
Open in Course

String Concatenation

Combining text

Concatenation joins strings. Use +: string full = first + " " + last;. This creates a new string combining all parts. Original strings remain unchanged. Result contains chars left to right.

You can concatenate variables, literals, and single characters. The operation returns a new string, so you can chain additions. Each + creates intermediate strings. Concatenation is convenient but can be slow in loops.

Each + allocates new memory. For building long strings, += or append() is more efficient because they modify in place.