The Overloading of Operator << and >>

class String {
public:
    friend ostream& operator<<(ostream&, const String&);
    friend istream& operator>>(istream&, String&);
    //other members
private:
    char *str;
};

ostream& operator<<(ostream& os, const String& str){
    int i=0;
    while (*(str.str+i)!='
class String {
public:
friend ostream& operator<<(ostream&, const String&);
friend istream& operator>>(istream&, String&);
//other members
private:
char *str;
};
ostream& operator<<(ostream& os, const String& str){
int i=0;
while (*(str.str+i)!='\0') os<<*(str.str + i++);
return os;
}
istream& operator>>(istream& is, String& str){
is>>str.str;
return is;
}
') os<<*(str.str + i++); return os; } istream& operator>>(istream& is, String& str){ is>>str.str; return is; }

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注