415
In this example we show how to concatenate 2 strings in C++
We will use the + operator to join 2 strings from the user
Example
#include <iostream> using namespace std; int main() { string myString1, myString2, result; cout << "Enter string 1: "; getline (cin, myString1); cout << "Enter string 2: "; getline (cin, myString2); result = myString1 + myString2; cout << "Concatenated String = "<< result; return 0; }
This was my test run
Enter string 1: This is a Enter string 2: test string Concatenated String = This is a test string