Objects of a class normally receive stream input via a friend function called operator>>. Here is an example of such a friend function. #include <iostream> using namespace std; class Fred { public: friend istream& operator>> (istream& istr, Fred& x) throw(); protected: int i_; }; istream& operator>> (istream& istr, Fred& x) throw() { istr >> x.i_; return istr; } The Fred argument of operator>> is passed by reference (as opposed to const reference). This allows operator>> to change the caller's Fred, which is, of course, the whole point of stream input. |