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

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.