Article View: comp.lang.c++.moderated
Article #8Re: Re-Routing streams
From: J. Kanze
Date: Fri, 15 Dec 1995 15:56
Date: Fri, 15 Dec 1995 15:56
31 lines
1949 bytes
1949 bytes
X-Original-Date: 15 Dec 1995 14:21:37 +0100
Kyle Lussier (lussier@aviator.cis.ufl.edu) wrote:
|> How do I get re-route, or overload the standard streams to send output
|> to somewhere else? Specifically I want all messages to stderr to be
|> sent to a file and all messages to stdout to be sent to a file.
Generally, this will be handled before invoking the program, in a system
dependant way.
Once the program is started, if your iostream library conforms to the
draft standard (precious few do), it is possible to modify the streambuf
that the stream uses, thus:
filebuf logFile( "logfile.name" ) ;
cerr.rdbuf( &logFile ) ;
This is just a quick example. Obviously, you will probably want some
error handling. And being a bit paranoid, I would probably save the
preceding streambuf*, and restore it at program end.
--
James Kanze (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils, itudes et rialisations en logiciel orienti objet --
-- A la recherche d'une activiti dans une region francophone
[ comp.lang.c++.moderated is a moderated newsgroup. Submit articles ]
[ to <c++-submit@netlab.cs.rpi.edu>. The moderation policy can be ]
[ retrieved from <http://netlab.cs.rpi.edu/~cppmods/guide.html>. ]
[ Moderators can be reached at: c++-request@netlab.cs.rpi.edu. ]
Technical Details
Message-ID:
<4as5rd$ck2@netlab.cs.rpi.edu>Path:
arc1-ca.pugleaf.net!kbad.eglin.af.mil!rpi!not-for-mailReferences:
<4aq1ig$1u2@netlab.cs.rpi.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!kbad.eglin.af.mil!rpi!not-for-mail From: kanze@gabi-soft.fr (J. Kanze) Newsgroups: comp.lang.c++.moderated,comp.lang.c++ Subject: Re: Re-Routing streams Followup-To: comp.lang.c++.moderated,comp.lang.c++ Date: 15 Dec 1995 15:56:29 -0000 Organization: GABI Software, Sarl. Sender: cppmods@netlab.cs.rpi.edu Approved: Dietmar.Kuehl@uni-konstanz.de Message-ID: <4as5rd$ck2@netlab.cs.rpi.edu> References: <4aq1ig$1u2@netlab.cs.rpi.edu> NNTP-Posting-Host: netlab.cs.rpi.edu