I am using a library that is printing a warning message to cout or cerr. I don\'t want this warning message to reach the output of my program. How
Use ios::rdbuf:
#include
void foo()
{
std::cout << "Boring message. " << std::endl;
}
int main()
{
ofstream file("/dev/null");
//save cout stream buffer
streambuf* strm_buffer = cout.rdbuf();
// redirect cout to /dev/null
cout.rdbuf(file.rdbuf());
foo();
// restore cout stream buffer
cout.rdbuf (strm_buffer);
std::cout << "Interesting message." << std::endl;
return 0;
}