今天在两台机子上面运行 结果一个报错 另外一个没报错 一个是VC++6.0的英文版 没报错 中问版的报错了 郁闷 怎么回事
#include <iostream>
using namespace std;
class String
{
public:
String() { inside= new char(50);}//ok
String(char *get)
{for(int i=0;i<strlen(get);i++)
inside[i]=get[i];}
String(String& s1)
{
inside=new char (s1.length());
inside=s1.inside;
}//ok
int find(String& s2);
int length();//ok
~String () {}
void operator =(String& c1);//ok
String operator +(String& c2);//ok
friend istream& operator >>(istream &cin,String &o1);//ok
friend ostream& operator <<(ostream &cout,String &o2);//ok
bool operator > (String c3);
bool operator < (String c4);
char operator [](int x);//ok
private:
char *inside;
};
int String::find(String& s2)
{
if(s2.length()>length())
return -1;
else
{
int t=0,i=0;
for(;i<length(),t<s2.length();i++)
if(inside[i]==s2.inside[t])
t++;
if(t==s2.length())
return i-t;
else
return -1;
}
}
int String::length()
{
int len(0);
for(int i=0;inside[i]!='\0';i++,len++)
;
return len;
}
void String::operator =(String& c1)
{
inside=c1.inside;
}
String String::operator +(String& c2)
{
int t=length();
for(int nu=0;nu<c2.length()+1;nu++)
inside[nu+t]=c2.inside[nu];
return *this;
}
istream& operator >>(istream& cin,String& o1)
{
cin>>o1.inside;
return cin;
}
ostream& operator <<(ostream& cout,String& o2)
{
cout<<o2.inside;
return cout;
}
bool String::operator >(String c3)
{
if(strcmp(inside,c3.inside)==1)
return true;
else
return false;
}
bool String::operator <(String c4)
{
if(strcmp(inside,c4.inside)==-1)
return true;
else
return false;
}
char String::operator [](int x)
{
return *(inside+x);
}
int main()
{
String s1,s2,s3;
cin>>s1>>s2;
s3=s1+s2;
cout<<s3<<endl;
for(int i=0;i<s3.length();i++)
cout<<s3[i];
cout<<endl;
if(s1>s2)
cout<<s1<<" is more lager than "<<s2<<endl;
//cout<<s3.find(s2);
return 0;
}