🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++.moderated
Article #9

Re: Re-Routing streams

#9
From: Dietmar Kuehl
Date: Sat, 16 Dec 1995 15:39
36 lines
1907 bytes
X-Original-Date: 15 Dec 95 16:50:42 GMT

Hi,
Diego Novillo (diego@cs.ualberta.ca) wrote:
: X-Original-Date: 15 Dec 1995 05:47:10 GMT

: #include <iostream.h>
: ofstream     cout_file;

: void  redirectOutput(String fname)
: {

:    cout_file.open(fname);
:    cout = cout_file;
: }

This is not portable as the assignment is not part of the Standard C++
Library although some current implementations allow such an assignment
(I'm not sure whether a conforming compiler/library is allowed to
accept the above code). You can replace the used 'streambuf' using the
'rdbuf()' function. Thus you can replace the line with the assignment
by the following one:

     cout.rdbuf(cout_file.rdbuf());

This is portable. Note that you might want to remember the original
'streambuf' used and restore it prior to program termination.
--
dietmar.kuehl@uni-konstanz.de
http://www.informatik.uni-konstanz.de/~kuehl
I am a realistic optimist - that's why I appear to be slightly pessimistic

    [ 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: <4aup7l$ioa@netlab.cs.rpi.edu>
Path: arc1-ca.pugleaf.net!kbad.eglin.af.mil!rpi!not-for-mail
References: <4aq1ig$1u2@netlab.cs.rpi.edu> <4arah4$8g8@netlab.cs.rpi.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!kbad.eglin.af.mil!rpi!not-for-mail
From: kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl)
Newsgroups: comp.lang.c++.moderated,comp.lang.c++
Subject: Re: Re-Routing streams
Followup-To: comp.lang.c++.moderated,comp.lang.c++
Date: 16 Dec 1995 15:39:33 -0000
Organization: Fakultdt f|r Mathematik und Informatik
Sender: cppmods@netlab.cs.rpi.edu
Approved: harkness@airmail.net
Message-ID: <4aup7l$ioa@netlab.cs.rpi.edu>
References: <4aq1ig$1u2@netlab.cs.rpi.edu> <4arah4$8g8@netlab.cs.rpi.edu>
Reply-To: Dietmar.Kuehl@uni-konstanz.de
NNTP-Posting-Host: netlab.cs.rpi.edu