Subject: Restoring cout in Microsoft VC++? From: "David W. Coppit" Date: 1997/04/07 Message-Id: Newsgroups: comp.lang.c++ [More Headers] I've written some code for which I reassign cout to an object that I've created to handle Windows-based I/O. I'm having trouble restoring cout to its original state, however. Below is an example program that has an access error when it tries to print "test3". #include int main () { ostream_withassign tempOut; cout << "test1\n"; tempOut = cout; tempOut << "test2\n"; cout = tempOut; cout << "test3\n"; return (0); } Interestingly, I can assign a file pointer to cout and redirect to a file, but that's not what I want to do -- I want to restore its previous state. In a post on DejaNews, John Hinke said that one can use cout.rdbuf(&tempOut) to remap cout on ANSI compliant compilers, or cout.rdbuf() = &tempOut // works in Borland on non-ANSI compilers. Unfortunately, the Microsoft compiler doesn't seem to accept either. I've tried all sorts of combinations of pointers to streambufs and references to ostreams to get this to work, all to no avail. (Below are the overloads for the assignment operator in ostream_withassign.) Has any one saved and restored cout in Microsoft VC++? Thanks, David ------------------------------------------------------------------------- David Coppit - Graduate Student coppit@cs.virginia.edu The University of Virginia http://www.cs.virginia.edu/~dwc3q "Shine on you crazy diamond." - Pink Floyd