#include<iostream>
#include<stdlib.h>
using namespace std;
class string1
{
char name[30];
public:
string1()
{
}
string1(char *s)
{
strcpy(name,s);
}
string1 operator+(string1 s2)
{
string1 s3;
strcpy(s3.name,strcat(name,s2.name));
return s3;
}
friend ostream& operator<<(ostream &ob,string1 s);
};
ostream& operator<<(ostream &ob,string1 s)
{
ob<<s.name;
return ob;
}
int main()
{
char str1[20],str2[20];
cout<<"enter string:\t";cin>>str1;
cout<<"enter string:\t";cin>>str2;
string1 s1(str1),s2(str2),s3;
cout<<"string s1="<<s1<<endl;
cout<<"string s2="<<s2<<endl;
s3=s1+s2;
cout<<"string s3="<<s3<<"\n";
return 0;
}
#include<stdlib.h>
using namespace std;
class string1
{
char name[30];
public:
string1()
{
}
string1(char *s)
{
strcpy(name,s);
}
string1 operator+(string1 s2)
{
string1 s3;
strcpy(s3.name,strcat(name,s2.name));
return s3;
}
friend ostream& operator<<(ostream &ob,string1 s);
};
ostream& operator<<(ostream &ob,string1 s)
{
ob<<s.name;
return ob;
}
int main()
{
char str1[20],str2[20];
cout<<"enter string:\t";cin>>str1;
cout<<"enter string:\t";cin>>str2;
string1 s1(str1),s2(str2),s3;
cout<<"string s1="<<s1<<endl;
cout<<"string s2="<<s2<<endl;
s3=s1+s2;
cout<<"string s3="<<s3<<"\n";
return 0;
}
No comments:
Post a Comment