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
  • 22,097
  • 68
  • 188
  • 315

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
  • 355,277
  • 75
  • 744
  • 836
0

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

Hot Licks
  • 47,103
  • 17
  • 93
  • 151