[lug] simple iostream bug?
zlynx at acm.org
Thu Mar 14 17:39:57 MST 2002
A quick correction to myself. I was curious about the endl manipulator
thing and so I looked it up. The endl function is declared as ostream&
endl(ostream&). Basically. (Lots of template stuff in there with it.)
When used just as endl, it is a function pointer. The iostreams
library has a declaration to deal with these by calling the function
pointer on the stream.
So your TextHeader function should work fine if you just call it as cout
<< TextHeader << endl;
Jonathan Briggs wrote:
> This is because you are sending a ostream reference (the return value
> of TextHeader) into an ostream and it appears to be converting it into
> an unsigned long. This is probably because iostreams return true if
> the stream state is good and false if the stream state is bad (so you
> can do while( cout ), or similar things.)
> Just do TextHeader( cout ).
> If you want to be able to do cout << TextHeader (as a manipulator,
> like how endl is used) you'll need to do some more magic (Bear with
> me, I'm not sure I remember this perfectly. You may need to consult
> Create a manipulator class/struct: This can be anything, it doesn't
> have to be part of any hierarchy.
> If it takes an argument, you make the constructor take the arguments.
> If it doesn't take arguments, I think you need to create a global
> instance of your class (I _think_ endl is an instance of something.)
> Make a non-member function for ostream& operator<<(ostream&,
More information about the LUG