4.10 Providing Class Instances of the iostream Operators

// [3/2/2009 wind] /************************************************************************/ /* Essential C++ P128 */ /************************************************************************/ #include <iostream> using namespace std; class Circular{ public: Circular( double r_old ) :radious( r_old ){} void set_radious( double r_old ){ this->radious = r_old; } double get_radious() const{ return radious; } private: double radious; }; ostream& operator<< ( ostream &os, const Circular &circular ){ os<<" the circle's radious is :"<<circular.get_radious()<<endl; return os; } istream& operator>> ( istream &is, Circular &circular ){ double radious = 0; cout<<"please input the radious:"; is>>radious; circular.set_radious(radious); return is; } int main(){ Circular c(4.4); cin>>c; cout<<c; return 0; } 

你可能感兴趣的:(4.10 Providing Class Instances of the iostream Operators)