C++ Program to concatenate two strings using 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++

Run it Now
#include<iostream>
using namespace std;

int main() {

    string first;
    string second;
    string last;

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

    cout << "\nEnter Second String value :";
    getline(cin, second);

    last = first + second;

    cout << "\nAfter Concatenate String is :" << last;

    return 0;
}

Output:

Enter First String value :C++
Enter Second String value :JAVA
After Concatenate String is :C++JAVA