🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

redefining stdout for all C/C++ output calls

#66
From: Kyle F. Downey
Date: Mon, 08 Apr 1996 21:40
28 lines
1623 bytes
Is there any way to redefine stdout that will work for both C-style
(printf, etc.) and C++-style (streams) output? I would want a C++
method that does this

void f() {
	printf("Here's a C-style output line.\n");
	cout << "Here's another using streams..." << endl;
}

to send the output to a different stream. I know there's tie() for
streams, but what about printf()? The idea here is to take a
text-based C++ program and "capture" all screen writes to send them to
an GUI window "stream." I want to do it so the text program need not be
rewritten. So you would take the main() function of the program and
call it, say, tmain() and pass it as a function pointer to a program
that would run it after redefining stdout.

Any ideas?

(If you've seen the SIOUX library under the Metrowerks C/C++ compiler,
you'll know what I am thinking about.)

--kd

      [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
      [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
      [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
      [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
Technical Details
Message-ID: <4kc14s$iai@netlab.cs.rpi.edu>
Path: arc1-ca.pugleaf.net!kbad.eglin.af.mil!rpi!not-for-mail

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!kbad.eglin.af.mil!rpi!not-for-mail
From: Kyle.F.Downey@williams.edu (Kyle F. Downey)
Newsgroups: comp.lang.c++.moderated,comp.lang.c++
Subject: redefining stdout for all C/C++ output calls
Date: 8 Apr 1996 21:40:44 -0000
Organization: Williams College, Williamstown MA
Sender: cppmods@netlab.cs.rpi.edu
Approved: vandevod@cs.rpi.edu
Message-ID: <4kc14s$iai@netlab.cs.rpi.edu>
NNTP-Posting-Host: netlab.cs.rpi.edu
X-Original-Date: 8 Apr 1996 13:55:41 -0400