Hi,
Here is what I am trying to achieve. I would like to have a stream, defaulting to outputting to std::cout
but that could work with std::cerr
too, that allows overwriting the last outputted line.
I am aware this will not work with seekp because std::cout is not seekable. The way I circumvent this is by instead outputting '\b'
characters. I also know this solution does not allow to go back one line up and that's fine.
I managed to get a solution but it is not nice (by the way, the version given in the link works with the real console even though it does not work with ideone - ideone shows \b
as a blank character). I would like an interface like the standard streams. Something like:
Logger log(std::cerr);
log << "hello" << 1 << erase << "hi" << std::endl;
This should output "hello1\b\b\b\b\b\bhi"
on std::cerr
and the user will only see "hi"
.
I managed to get something close by inheriting std::ostream
and std::streambuf
but it does not compile (see link).
What would be a solution to this problem? Please note that I am not particularly attached to my solution. Any solution letting me achieve the "stream way" is okay.