std::ostream not the best place to implement filtering. It does not have the corresponding virtual functions so you can do this.
You will probably want to write a class derived from std::streambuf containing wrapped std::ostream (or wrapped std::streambuf ) and then create std::ostream using this std::streambuf .
std::streambuf has a virtual overflow function that you can override and use to change bytes before passing them to the class of completed output.
source share