Well here is a really good reference (apparently not that good because I had to fix some of the code) for overloading the io operators. I can't tell you much more with out knowing the details of your class, however I can say that the beauty of the stream operators is that they provide an interface to any stream type object not just stdin and stdout. Here is a little example from the site:
#include
using namespace std;
class Point
{
private:
double m_dX, m_dY, m_dZ;
public:
Point(double dX=0.0, double dY=0.0, double dZ=0.0)
{
m_dX = dX;
m_dY = dY;
m_dZ = dZ;
}
friend ostream& operator<< (ostream &out, Point &cPoint);
friend istream& operator>> (istream &in, Point &cPoint);
double GetX() { return m_dX; }
double GetY() { return m_dY; }
double GetZ() { return m_dZ; }
};
ostream& operator<< (ostream &out, Point &cPoint)
{
// Since operator<< is a friend of the Point class, we can access
// Point's members directly.
out << cPoint.m_dX << " " << cPoint.m_dY << " " << cPoint.m_dZ << std::endl;
return out;
}
istream& operator>> (istream &in, Point &cPoint)
{
in >> cPoint.m_dX;
in >> cPoint.m_dY;
in >> cPoint.m_dZ;
return in;
}
IMO the best way to think about overloading these operators is to leverage previously written >>
and <<
and that way you sort of build a chain and it becomes extremely simple and convenient to implement these operators.