Topic: Symantec C++ & Think Project Manager & Macintosh io probs
Author: custer@wrc.wrgrace.com (Linda Custer)
Date: Thu, 3 Jun 1993 00:21:44 GMT Raw View
I'm having some problems implementing the "new-style io" of C++ using
Symantec C++ under the THINK Project Manager (C++/TMP) for Macintosh.
First problem:
I can't seem to use setprecision and setwidth correctly. I want to do the
following:
// CPlusLib, IOStreams, and ANSI++ are in the project, as is the
// following source code:
#include <iostream.h>
#include <fstream.h>
fstream in;
fstream out;
double dbl;
fopen.in("in");
fopen.out("out");
in >> dbl;
// do the neat stuff on dbl ...
out << setprecision(6) << setw(17) << dbl << endl;
fclose.in();
fclose.out();
The compiler tells me that the functions setprecision() and setw() are
not defined. But I have included everything important, no? Instead, I seem
to be forced to write the last line above as
out.precision(6);
out.width(17);
out << dbl << endl;
That works. Is there an error in the compiler? The libraries? The headers?
My comprehension of C++ and Gray? All of the above?
Second problem:
I wanted to perform a manipulation on a batch of doubles. From Gray p. 335,
I thought that conditionals on a stream would detect problems automatically.
So I modified the core code above to read
for (;;) {
if (!(in >> dbl)) return;
// do the neat stuff on dbl ...
out << dbl << endl;
}
to swallow a double. This was in a for(;;) loop that kept doing things with
doubles until it ran out. When the file "in" included doubles _with no
carriage return after the last double_, the program did what I expected. It
read once for each double and then kindly returned. HOWEVER, when the file
"in" included doubles _and one end carriage return at the end of the file_,
the program would try once too often. It would
When I printed out rdstate of the buffers as
out << in.rdstate();
I got 0 when I started, 1 after I had tried to read the last double in the
list the first time (since 1 = the eof bit), and 3 once I tried to read it a
second time (3 = eof bit + failed bit). The program _then_ returns once the
bit is 3 and doesn't try again. What I don't understand is why the first eof
error doesn't get the program to return. Just what _is_ returned by (in >>
dbl)? Why was this so dependent on whether there was a terminal '\n' in the
input file or not?
Interestingly,
in >> dbl;
if (in.eof()) return;
works fine.
Last comment:
I know the libraries came from Symantec products for the DOS world, but could
they please duplicate the file
strstrea.h
as
strstream.h
for portability's sake. That way, we could refer to the file by either name
and still be ok.
Thanks in advance for any help!
Linda Custer (custer@wrc.wrgrace.com)
"A fool, a fool, I met a fool in the forest. A motley fool; a miserable
world." -Shakespeare
Author: custer@wrc.wrgrace.com (Linda Custer)
Date: Fri, 4 Jun 1993 02:07:06 GMT Raw View
In <LMC012@wrc.wrgrace.com>, I said:
>>>>>
I'm having some problems implementing the "new-style io" of C++ using
Symantec C++ under the THINK Project Manager (C++/TMP) for Macintosh.
<<<<<
(Much codeage eliminated for brevity.)
jorge@dca.fee.unicamp.br (Jorge Diz) responded and suggested I tried
including <iomanip.h>. This solved problem #1. Thanks!
Linda Custer (custer@wrc.wrgrace.com)
"A fool, a fool, I met a fool in the forest. A motley fool; a miserable
world." -Shakespeare