I am using a shared library whose functions are doing std::cout everywhere. Is is possible to do anything at the caller level wherein I can suppress the cout outout or redirect it to some location?
Is it even possible to attempt such a thing in c++.
Something like this, just make function wrappers for your library calls that would redirect cout
.
int main( void )
{
std::ofstream lStream( "garbage.txt" );
std::streambuf* lBufferOld = std::cout.rdbuf();
std::cout.rdbuf( lStream.rdbuf() );
std::cout << "Calling library function" << std::endl;
std::cout.rdbuf( lBufferOld );
std::cout << "Normal output" << std::endl;
std::cout.rdbuf( lStream.rdbuf() );
std::cout << "Calling another library function" << std::endl;
std::cout.rdbuf( lBufferOld );
std::cout << "Another normal output" << std::endl;
lStream.close();
return ( 0 );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With