PDA

View Full Version : سوال: سربارگذاری عملگرها



victoria
یک شنبه 24 خرداد 1388, 12:54 عصر
سلام من یه برنامه در مورد سربارگذاری عملگرها نوشتم که متاسفانه 23 تا Error میده خواستم ببینم کسی می تونه راهنماییم کنه؟

#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<string.h>
class string{
friend ostream & operator<<(ostream &,const string &);
friend istream &operator>>(istream &,string &);
public:
string();
void getstring();
string &operator+=(const string &);
string &operator=(const string &);
bool operator==(const string &) const;
bool operator!() const;
bool operator<(const string &);
bool operator<=(const string &);
bool operator>(const string &);
bool operator>=(const string &);
bool operator!=(const string & right) const;
return!(*this==right)const;
private:
int length;
char st[80];
void setstring(char*);
};
string::string(){
st[0]="\0";
}
void string::getstring(){
cout<<"enter your string:";
gets(st);
this->getstring();}
void string::setstring(char*s+2){
strcpy(this->st,st2);}
string &string::operator=(const string & right){
setstring(right.st);
return (*this);
}
string &string::operator+=(const string &right){
strcat(this->st,right.st);
return(*this);}
bool &string::operator==(const string &right){
return(!stcmp(this->st,right.st);}
bool &string::operator<(const string &right){
return(strcmp(this->sr,right.st)<0);}
bool &string::operator<=(const string &right){
return(strcmp(this->st,right.st)<=0);
bool &string::operator>(const string &right){
return(!(*this<=right));}
}
bool &string::operator>=(const string &right){
return(!(*this<right);
}
bool &string::operator!(const string &right)
{return (st[0]="\0");
}
void string::gerlength(){
length=strlen(this->st);}
ostream &operator<<(ostream &output,const &s){
output<<"\n"<<s.st;
return output;}
istream &operator>>(istream &input, const string &s){
input>>s.st;
s.length();
return input;
}
void main(){
string s1,s2,s3,s4;
cout<<"\n please enter a string:";
cin>>s1;
cout<<"\n please enter a string:";
s2.getstring();
s3=s1;
s3+=s2;
s4=s2;
cout<<"\n s4==s2 ?";
cout<<(s4==s2)? "true" : "false";
cout<<"\n s4<s2";
cout<<(s4<s2) ? "true" : "false";
}

حامد مصافی
یک شنبه 24 خرداد 1388, 20:13 عصر
سوال شما در مورد کل این کد است؟ گمان نمکنم اینجه کسی به این حد وقت آزاد داشته باشد که این کد را کامپایل کرده و بعد از پی بردن به ایراد ها آن ها را برطرف کند، من به شخصه حتی آن را نخواندم.
- متن خطای دریافتی را قید کنید.
- در حوضه مشخص و واضحی سوال کنید.
تا سریعتر به جواب برسید.