I have a library, which sends messages to the console using std::cout and std::cerr.
I know, I can redirect that in my GUI Application. But, what I wonder is, if there is a way to detect if cout or cerr was used before the message is actually flushed?
Background: I would like to be able to change the text color and put a string like "Error: " in front of the message, if the text comes from cerr.
E.g. if there was a line
cerr << "File not found" << endl;
in the library, is there a kind of callback or event that I can use to make sure that I can execute a
cerr << "Error: ";
from my side before the original error message without touching the original library?
Note that redirecting to a string as in the question redirect stdout/stderr to a string would require me to know when the library creates an output and do something with that string. Instead I am looking for a sort of automatic mechanism.