Advertisement

Concatenate Object String in C++ program | Code with abuzar

Types of Concatenate String object in C++ 


There are various method of Concatenate string object , But we have to use the Simple method of Concatenate string.

Example :

#include<iostream>
using namespace std;
int main()
{
string s1,s2,result;

cout<<"Enter the string 1 :";
getline(cin,s1);

cout<<"Enter the string 2:";
getline(cin,s2);

result = s1+s2;
cout<<"Final answer is :"<<result;

 return 0;
}


Output :

Enter the string 1 :C++ is a 

Enter the string 2: Programming Language 

Final answer is :C++ is a Programming Language 


And this is the next method of Concatenate is C-type String and In this string we use the (Strcat). Now we can see that how we can use the strcat function.


Example : 


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
 char s1[20], s2[20];

 cout<<"Enter the string s1 "<<endl;
 cin.getline(s1,20);

 cout<<"Enter the string s2 "<<endl;
 cin.getline(s2,20);

 strcat(s1,s2);

 cout<<"s1 :"<<s1<<endl;
 cout<<"s2 :"<<s2<<endl;

    return 0;
}

Output :

Enter the string s1 

Java is a 

Enter the string s2 

Advanced Language 

 s1 : Java is a Advanced Language 

 s2 : Advanced Language 


So,  there are the method to concatenate Object string.


This article is contributed by Mohd abuzar. If you like code with abuzar or want or contributed with us so mail at- abuzar.abuzar.mohd325@gamail.com

Please ! Comment if you find anything incorrect in this website.





Post a Comment

0 Comments