StephQ wrote:
On Mar 6, 1:39 pm, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
StephQ wrote:
At the moment I have a void member function (of a given class) that
takes as input an obj of class type ofstream and write some debug
information to it using the << operator.
I would like to modify the code so that the function returns a
"stream" that can be "sent" to cout or to a file using <<, as this
would give me more flexibility.
I used " " because I'm not sure I'm not using the correct terms
here. :P
What about returning a std::string? You could send that to cout or a
file
using <<. So it seems to fit the description.
Alternatively, you could also make your function use an ostream &
instead
of a ofstream &.
Best
Kai-Uwe Bux
See my reply above.
See my reply to that reply.
I have never used ostream before. Do you have a link to a reference /
tutorial about it and streams in general?
Unfortunately, computer books are incredibly booring to me (with very,
_very_ few exceptions). I don't read them unless I have to look up
something. For that, I usually refer to the C++ standard. However, it
appears to be general consensus in this forum that this is not a good
recommendation.
However, for the case you mentioned, I take it that you have some function
void log ( std::ofstream & the_stream ) {
...
}
I would try to just changing it to
void log ( std::ostream & the_stream ) {
// same body
}
Unless you use file-specific methods (for which I don't see a need), you
should get away with that small change.
Umm.. I don't see a change. I think you meant to change it to: