This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Attaching cout || cerr to an ostream
- To: libstdc++ at gcc dot gnu dot org
- Subject: Re: Attaching cout || cerr to an ostream
- From: Gerhard Wesp <gwesp at cosy dot sbg dot ac dot at>
- Date: Fri, 23 Feb 2001 16:16:27 +0100
- References: <NEBBLDHMLKKHEAKFKMIHKEMBCDAA.laurent.marzullo@be.sema.com>
- Reply-To: gwesp at cosy dot sbg dot ac dot at
> Anyone know how to attach cout or cerr (fd 1 or fd 2) to an ostream ?
>
> I was used to do something like this with the old libstdc++ :
>
> ------------------------------------------------
> ofstream l_try;
> string l_output;
>
> if ( l_output == "cerr" )
> l_try.attach( 2 );
> else if ( l_output == "cout" )
> l_try.attach( 1 );
> else
> l_try.open( l_output.c_str() );
> ------------------------------------------------
i'm not quite sure as to what exactly you're trying to do, but perhaps
it could be something along the lines of
if ( l_output == "cerr" )
l_try.rdbuf( std::cerr.rdbuf() ) ;
// etc.
after this, output to l_try will go whereever std::cerr output goes.
hth,
-gerhard