Mega Code Archive

 
Categories / C++ Tutorial / Operator Overloading
 

Complex logic in ostream operator

#include <iostream> using namespace std; class Line {   int x; public:   Line(int i) { x=i; }   friend ostream &operator<<(ostream &stream, Line o); }; ostream &operator<<(ostream &stream, Line o) {   register int i, j;   for(i=0; i<o.x; i++)      stream << "*";   stream << "\n";   return stream; } int main() {   Line a(14), b(30), c(40);   cout << a << b << c;   return 0; } ************** ****************************** ****************************************