In this article, we will unveil the various ways of performing string concatenation in the C++ language. This method can be used for various purposes while programming. But in general, the concept is the same as combining two strings from different locations and placing them together.
Techniques of String Concatenation in C++
The following techniques can be taken into consideration while concatenating strings in C++:
- C++ concatenate [+] operator
- The strcat[] method
- C++ append[] function
- Using C++ for loop for concatenation
1. C++ ‘+’ operator for String Concatenation
C++ '+' operator
can be used to concatenate two strings easily.
The ‘+’ operator adds the two input strings and returns a new string that contains the concatenated string.
Syntax:
string1 + string2;
Example:
#include
using namespace std;
int main[]
{ string str1="", str2="";
coutstr1;
coutstr2;
string res = str1 + str2;
cout