I want to define a class MyStream
so that:
MyStream myStream;
myStream << 1 << 2 << 3 << std::endl << 5 << 6
Your overloaded operators of the MyStream
class have to set a previous-printed-token-was-endl flag.
Then, if the next object is printed, the [blah]
can be inserted in front of it.
std::endl
is a function taking and returning a reference to std::ostream
. To detect it was shifted into your stream, you have to overload the operator<<
between your type and such a function:
MyStream& operator<<( std::ostream&(*f)(std::ostream&) )
{
std::cout << f;
if( f == std::endl )
{
_lastTokenWasEndl = true;
}
return *this;
}