Possible Duplicate:
Operator overloading
The questions to overload the >>\<< operators to make them read/write from/to a stream?
can anyone explain how to do this please
Possible Duplicate:
Operator overloading
The questions to overload the >>\<< operators to make them read/write from/to a stream?
can anyone explain how to do this please
Define
std::ostream &operator<<(std::ostream &out, Foo const &x)
{
// write a representation of x to out
// you can use << on x's members
return out;
}
std::istream &operator>>(std::istream &in, Foo &x)
{
// read a representation of a Foo from in
// and use it to modify x
return in;
}
appropriately.
Wouldn't you just define operator >>
or operator <<
?