Objects of a class are normally printed via a friend function called operator<<. Here is an example of such a friend function. #include <iostream> using namespace std; class Fred { public: friend ostream& operator<< (ostream& ostr, const Fred& x) throw(); protected: int i_; }; ostream& operator<< (ostream& ostr, const Fred& x) throw() { ostr << x.i_; return ostr; } The function operator<< is a friend rather than a member, so the Fred parameter appears on the right side of the <<. |