delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/12/19/14:37:47

Sender: maeder AT dhcppc3
Newsgroups: comp.os.msdos.djgpp,gnu.g++.help
Subject: Re: ofstream and rdbuf()
References: <atpq2h$1ef1r$1 AT ID-79865 DOT news DOT dfncis DOT de> <atrmeg$1v1a1$1 AT ID-79865 DOT news DOT dfncis DOT de>
From: Thomas Maeder <maeder AT glue DOT ch>
Date: 19 Dec 2002 20:00:43 +0100
Message-ID: <m2fzstg7fo.fsf@glue.ch>
Lines: 36
User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Military Intelligence)
MIME-Version: 1.0
NNTP-Posting-Host: 80.218.15.133
X-Trace: news.swissonline.ch 1040324438 80.218.15.133 (19 Dec 2002 20:00:38 +0100)
X-Complaints-To: abuse AT swissonline DOT ch
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Alex Vinokur" <alexvn AT bigfoot DOT com> writes:

> ===============
> Windows 2000
> DJGPP 2.03
> GNU gcc/gpp 3.1
> ===============
> 
> 
> I have got compilation errors related to ofstream and rdbuf().
> Is there any way to do what I want to ?

A much shorter test program would have been enough ...


> #include <iostream>
> #include <fstream>
> #include <assert.h>
> using namespace std;
> 
> int main ()
> {
> streambuf *psbuf_cout;
> ofstream file1;
>   file1.open ("f1.txt");
>   psbuf_cout = cout.rdbuf();
>   file1.rdbuf(psbuf_cout); // Line#61

There is an overload of rdbuf() in std::ofstream which hides the
std::ostream::rdbuf() version you attempt to call. Your options include:

file1.std::ostream::rdbuf(psbuf_cout);

and

static_cast<std::ostream &>(file1).rdbuf(psbuf_cout);

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019