I am looking for a way of adding a prefix to an ostream, pass it down to other functions so that their outputs are prefixed and then remove it to continue.
Check the following pseudocode:
...
void function(ostream &out){
out << "output 1\n";
out << "output 2\n";
}
cout << "Whatever\n";
add_suffix(cout,"function: ");
function(cout);
remove_suffix(cout);
...
With an output like:
...
Whatever
function: output 1
function: output 2
...
Looking at the docs of ostream they state that sentry might be used for prefixing/suffixing but i don't know how to do this if the intended use is what I want.
The ostream::sentry
documentation says:
sentry: Perform exception safe prefix/suffix operations