#include<iostream>
#include<string.h>
using namespace std;
class String{
char* array;
public:
String(char *p){
array=new char[strlen(p)+1];
strcpy(array,p);
};
~String(){
delete array[];
};
friend ostream& operator<<(ostream&,const String&);
char operator[](int n){
int length=strlen(array);
if(n<length){
char &ret=*(array+n);
return ret;
}
else{
cout<<"Index out of range."<<endl;
}
}
String& operator+(const String& n){
char*temp=new char(strlen(array)+strlen(n.array)+1);
strcpy(temp.array);
strcat(temp,n.array);
delete []array;
array=temp;
return *this;
}
};
ostream& operator<<(ostream& output,const String& str){
output<<str.array;
return output;
}
int main(){
String string1("mystring"),string2("yourstring"),string3("herstring");
cout<<string1<<endl;
string1[7]='n';
cout<<string1<<endl;
string1[8]='n';
cout<<string1+string2+string3<<endl;
cout<<string1<<endl;
return 0;
}