I’d like to write a simple ostream which wraps an argument ostream and changes the stream in some way before passing it on to the argument stream. The transformation is something simple like changing a letter or erasing a word
What would a simple class inheriting from ostream look like? What methods should I override?
std::ostreamis not the best place to implement filtering. It doesn’t have the appropriate virtual functions to let you do this.You probably want to write a class derived from
std::streambufcontaining a wrappedstd::ostream(or a wrappedstd::streambuf) and then create astd::ostreamusing thisstd::streambuf.std::streambufhas a virtual functionoverflowwhich you can override and use to alter the bytes before passing them to the wrapped output class.