* g++ newbie prblem - gcc-3.0.3 vs gcc-2.95.3
@ 2002-01-18 6:31 Hillel (Sabba) Markowitz
2002-01-18 7:42 ` Claudio Bley
0 siblings, 1 reply; 3+ messages in thread
From: Hillel (Sabba) Markowitz @ 2002-01-18 6:31 UTC (permalink / raw)
To: gcc-help
The following program builds and runs fine under 2.95.3 but does not compile
under gcc-3.0.3 As a g++ newbie I must be doing something very obvious wrong.
Please respond via e-mail as I do not usually have access to the mailing list
archive.
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <fstream.h>
#include <unistd.h>
main()
{
ofstream *fout = new ofstream (dup(1));
*fout << "Hello World\n";
}
When compiling with gcc-3.0.3 I get
r.cc: In function 'int main()':
r.cc:9 no matching function for call to 'std::basic_ofstream<char,
std::char_traits<char> >::basic_ofstream(int)'
/usr/local/GCC-3.0/include/g++-v3/bits/std_iosfwd.h:84: candidates are:
std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(const
std::basic_ofstream<char, std::char_traits<char> >&)
/usr/local/GCC-3.0/include/g++-v3/bits/std_fstream.h:319:
std::basic_ofstream<_CharT, _Traits>::basic_ofstream(const char*,
std::_Ios_Openmode = (std::ios_base::out | std::ios_base::trunc)) [with
_CharT = char, _Traits = std::char_trats<char>]
/usr/local/GCC-3.0/include/g++-v3/bits/std_fstream.h:313:
std::basic_ofstream<_CharT, _Traits>::basic_ofstream() [with _CharT = char,
_Traits = std::char_traits<char>]
--
Said the fox to the fish, "Join me ashore".
The fish are the Jews, Torah is our water
Hillel (Sabba) Markowitz - sabbahem@bcpl.net
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: g++ newbie prblem - gcc-3.0.3 vs gcc-2.95.3
2002-01-18 6:31 g++ newbie prblem - gcc-3.0.3 vs gcc-2.95.3 Hillel (Sabba) Markowitz
@ 2002-01-18 7:42 ` Claudio Bley
2002-01-19 16:44 ` Hillel (Sabba) Markowitz
0 siblings, 1 reply; 3+ messages in thread
From: Claudio Bley @ 2002-01-18 7:42 UTC (permalink / raw)
To: Hillel (Sabba) Markowitz; +Cc: gcc-help
>>>>> "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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: g++ newbie prblem - gcc-3.0.3 vs gcc-2.95.3
2002-01-18 7:42 ` Claudio Bley
@ 2002-01-19 16:44 ` Hillel (Sabba) Markowitz
0 siblings, 0 replies; 3+ messages in thread
From: Hillel (Sabba) Markowitz @ 2002-01-19 16:44 UTC (permalink / raw)
To: Claudio Bley; +Cc: Claudio Bley, gcc-help
Claudio Bley wrote:
>
> >>>>> "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
Thank you for your response. I tried your suggestion and it does work.
However, we need to be able to outprint the results of fprintf to stderr
(legacy code already written). If the user specifies on the command
line that he wants to use a log file instead of stderr, then we want to
close the stderr and open the log file. In the command line parser we
have
close(2);
fopen(logFile, "w"):
From that point on, all fprintf(stderr, "..."); calls will be written to
the log file (or the screen if the command line switch did not trigger
the close and reopen.
g++-2.95.3 implemented this correctly, but g++3.0.3 do not. Is there a
recommended way to code this.
I would prefer not to have to change all the fprintf legacy code if I
can avoid it. It would be preferable if the code change also handled
cerr<< ...; as well as this is a mixed c, c++ set of routines and has
both legacy and new code. However, the main question is with the
fprintf.
As before, please respond to sabbahem@bcpl.net or
Sabba.Hillel@verizon.net as I do not have reliable access to the mailing
list.
--
Said the fox to the fish, "Join me ashore".
The fish are the Jews, Torah is our water.
Hillel (Sabba) Markowitz
sabbahem@bcpl.net, Sabba.Hillel@verizon.net
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-01-20 0:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-18 6:31 g++ newbie prblem - gcc-3.0.3 vs gcc-2.95.3 Hillel (Sabba) Markowitz
2002-01-18 7:42 ` Claudio Bley
2002-01-19 16:44 ` Hillel (Sabba) Markowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).