You are not logged in.
Hi, I'm facing a stupid problem. I have to work with a crappy C++ library which prints messages on screen using cout. I want to get rid of these messages, but I cannot modify the code (well, I could, but I cannot reinstall it so I have to live with the verbose library). My question is: is it possible to "mute" cout before invoking the library, so that it does not output anything? I'm thinking about redirecting it to a null device or something like this. Or maybe there's a nicer way (I hope )?
Thanks
Offline
From Here, you may be able to do something like:
int main() {
std::streambuf* cout_sbuf = std::cout.rdbuf(); // save original sbuf
std::ofstream fout("/dev/null");
std::cout.rdbuf(fout.rdbuf()); // redirect 'cout' to a 'fout'
// ...
std::cout.rdbuf(cout_sbuf); // restore the original stream buffer
}
Offline
Might want to do something similar to cerr if you want to be really sure nothing comes out of the library.
Offline
@Cerebral: thank you very much!
@scio: I only have to "mute" stdout, because this stupid library prints some useless warning messages on it, without having any "verbose" option to disable it. In my opinion, a library should never print to the stdout, or at least give the option to turn off the output.
Offline
Whatever works for you. I prefer libraries that allow you to set message handlers or read from a variable for errors.
In my opinion a library should never print anything, but if all you are worried about is stdout then you are all set
Edit: Oh, and you might want to add [SOLVED] to the subject.
Last edited by scio (2009-09-04 17:11:31)
Offline