This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Attaching cout || cerr to an ostream


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]