cout assign

Martin v. Loewis martin@mira.isdn.cs.tu-berlin.de
Wed Mar 31 23:46:00 GMT 1999


> I want to redirect cout to a file.  We have an assign operator for
> cout, but it doesn't work, and the source iostream.cc says it's not
> really supported.
> 
> So how do you make this work portably?

>From what I can see, assigning a different rdbuf should be portable.
For me,

  ofstream foo("tmp.foo");
  cout.rdbuf(foo.rdbuf());

seems to work. Assignment of streambufs is not supported: cout is an
ostream; assigning an ofstream would mean truncation.

Regards,
Martin



More information about the Gcc mailing list