g++ newbie prblem - gcc-3.0.3 vs gcc-2.95.3

Claudio Bley bley@cs.uni-magdeburg.de
Fri Jan 18 07:42:00 GMT 2002


>>>>> "Hillel" == Hillel (Sabba) Markowitz <sabbahem@bcpl.net> writes:

    Hillel> The following program builds and runs fine under 2.95.3
    Hillel> but does not compile under gcc-3.0.3 As a g++ newbie I
    Hillel> must be doing something very obvious wrong.

    Hillel> Please respond via e-mail as I do not usually have access
    Hillel> to the mailing list archive.

    Hillel> #include <stdio.h> #include <stdlib.h> #include
    Hillel> <iostream.h> #include <fstream.h> #include <unistd.h>
    Hillel> main() { ofstream *fout = new ofstream (dup(1)); *fout <<
    Hillel> "Hello World\n"; }

[snip]

The C++ Standard does *not* specify a facility to assign a file
descriptor to a file stream because file descriptors are OS dependent.

If you want to redirect standard I/O channels you should assign the
stream buffers of stream objects to each other:

ostream ostr(0);
ostr.rdbuf (cout.rdbuf ());


Claudio



More information about the Gcc-help mailing list