标签: C++

  • 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; }
  • 尝试贴一段代码

    尝试贴一段代码,看看代码高亮功能能不能正常工作。

    (更多…)