0

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

Community
  • 1
  • 1
124697
  • 21,137
  • 63
  • 182
  • 307

2 Answers2

1

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.

Fred Foo
  • 342,876
  • 71
  • 713
  • 819
0

Wouldn't you just define operator >> or operator <<?

Hot Licks
  • 46,205
  • 16
  • 90
  • 149