Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!ahodgson From: ahodgson@athena.mit.edu (Antony Hodgson) Newsgroups: comp.lang.c++ Subject: Re: Assigning cout in Turbo C++ Message-ID: <1991Mar15.175746.17824@athena.mit.edu> Date: 15 Mar 91 17:57:46 GMT References: <27DEC60D.18984@maccs.dcss.mcmaster.ca> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Lines: 25 In article <27DEC60D.18984@maccs.dcss.mcmaster.ca> walkerd@maccs.dcss.mcmaster.ca (David Walker) writes: >Summary : Can you reassign cout to a file? >All I want to do is reassign cout to a file so that all screen >output becomes file output. I'm not sure if you can simply assign cout to a file, but the following works (I think - I did it once and don't have my code close at hand) and probably does what you want. ofstream f( "output.fil" ); ostream sout; // for Standard OUT // put to the screen sout = cout; sout << "Hi there"; // to a file sout = f; sout << "Into the file"; Hope this helps. Tony Hodgson ahodgson@hstbme.mit.edu