Advertisement

C++ Program to concatenate two strings using the string class


In this program, You will learn how to concatenate two strings using string class in C++.


first = "c++", second = "java"

string last = first + second;

Example: How to concatenate two strings using string class in C++

#include<iostream>
using namespace std;

int main() {

    string first;
    string second;
    string last;

    cout << "Enter first string value:";
    getline(cin, first);

    cout << "Enter second string value:";
    getline(cin, second);

    last = first + second;

    cout << "After concatenated string is:" << last;

    return 0;
}

Output:

Enter first string value:Xiith
Enter second string value:.com
After concatenated string is:Xiith.com