Is it possible to manipulate the std::ostream to prepend a string when
performing output, e.g.
// manipute std::cout to prepend "prefix "
std::cout << "hallo" << std::endl;
// results in "prefix hallo"
I need this to overwrite the "<<" operator for MyClass in a recursive
way, e.g.
std::ostream&
operator<<( std::ostream& stream, MyClass const& myClass )
{
// do some output
// prepend '\t' to stream, how?
stream << myClass.member_ << '\n'; // recursive call of << operator
// remove prefix '\t' from stream
return stream;
}
when MyClass has a pointer to another MyClass as a member
(MyClass const* member_). I like to prepend tabs when streaming the
members without saving the prefixes in MyClass.
Thanks,
Boris
performing output, e.g.
// manipute std::cout to prepend "prefix "
std::cout << "hallo" << std::endl;
// results in "prefix hallo"
I need this to overwrite the "<<" operator for MyClass in a recursive
way, e.g.
std::ostream&
operator<<( std::ostream& stream, MyClass const& myClass )
{
// do some output
// prepend '\t' to stream, how?
stream << myClass.member_ << '\n'; // recursive call of << operator
// remove prefix '\t' from stream
return stream;
}
when MyClass has a pointer to another MyClass as a member
(MyClass const* member_). I like to prepend tabs when streaming the
members without saving the prefixes in MyClass.
Thanks,
Boris
Comment