I am working upon this problem.
Write a String class and overload the + operator to mix two strings such that a new string is created with one character from each string pieced together until all the characters are mixed. For example • "1234567890" + "QWERTYUIOP" = "1Q2W3E4R5T6Y7U8I9O0P"
Can you help me out in concatenating the characters of two strings?
This is the code I have written :
#include "stdafx.h"
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
class MY_String : public string
{
public:
char *rep;
MY_String(){}
MY_String(char *tem)
{
rep = new char[strlen(tem)+1] ;
strcpy(rep,tem);
}
MY_String operator + (const MY_String &rhs)
{
char *temp;MY_String obj11("1234567890");
temp= new char[strlen(rep) + strlen(rhs.rep)+1];//cout<<"TEMP::"<<rhs.rep<<endl;
temp = strcat(rep,rhs.rep);
return MY_String(temp);
}
};
int main()
{
MY_String obj1("1234567890");
MY_String obj2("QWERTYUIOP");
MY_String obj3;
obj3 = obj1+obj2;
cout<<obj3.rep;
return 0;
}