Suppose I want to rot13 every string passed to cout (or another ostream), so that, say cout<<"Foo Bar Baz.;" (or even cout<<rot13<<"Foo Bar Baz.";) outputs Sbb One Onm.
How would I go about doing that?
(My first idea was to replace cout’s streambuf with a streambuf-derived class that would do all the work. But seeing as the original streambuf is responsible for directing stuff to the console… that didn’t work out at all.)
You can write your own stream that overload operator<< for char*, std::string and others and prints a transformed text.
The next step is to declare a global variable of this type and then a macro that replaces cout with the new variable.
And then all instances of cout will become cout_rot13.