usually :
std::ostream& operator <<(std::ostream& ostrm)
{
ostrm << "Hello its overloaded\n";
return ostrm;
}
std::istream& operator >>(std::istream& istrm)
{
cout<<"Enter a number : ";
istrm >> MyClass::myNumber;
return istrm;
}
note overloading the << operator should be a friend, so you can use it like this :
cout << myClassVar;
if not then you would use this syntax :
myClassVar <<cout;
which is confusing.
Last edited by firstPerson; Aug 21st, 2009 at 2:59 pm.
Reputation Points: 840
Solved Threads: 594
Senior Poster
Offline 3,862 posts
since Dec 2008