Skip to content

Instantly share code, notes, and snippets.

@ravikiran0606
Created July 27, 2016 15:41
Show Gist options
  • Save ravikiran0606/5abaaa25860031830d5b68b6b5648ea8 to your computer and use it in GitHub Desktop.
Save ravikiran0606/5abaaa25860031830d5b68b6b5648ea8 to your computer and use it in GitHub Desktop.
C++ program to perform string concatenation:
#include<iostream>
#include<cstring>
using namespace std;
class sstring{
char* s;
int len;
public:
sstring();
sstring(char *a);
void concat(sstring x,sstring y);
void display();
};
sstring::sstring(){
len=0;
s=new char[len+1];
}
sstring::sstring(char *a){
len=strlen(a);
s=new char[len+1];
strcpy(s,a);
}
void sstring::concat(sstring x,sstring y){
len=x.len+y.len;
s=new char[len+1];
strcpy(s,x.s);
strcat(s," ");
strcat(s,y.s);
}
void sstring::display(){
cout<<"\nThe string is "<<s<<endl;
}
int main()
{
char x[100];
cout<<"Enter the first string ";
cin>>x;
sstring a(x);
cout<<"\nEnter the second string ";
cin>>x;
sstring b(x);
sstring c;
c.concat(a,b);
c.display();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment