Boost logo

Boost :

From: Joel Young (jdy_at_[hidden])
Date: 2001-05-30 15:50:39


>on 5/27/01 7:07 PM, Gregory Seidman at gseidman_at_[hidden] wrote:
>> Now, what isn't platform-dependent is the C stdio FILE*. Why isn't there a
>> constructor for {i/o}fstream which takes a FILE*? Shouldn't there be? That
>> would be platform-independent and decidedly useful. It would also reduce
>> wrapping a file descriptor to call fdopen() on it first.
>>
>> Is there interest in this? Has someone else done it and I just don't know

From: Daryle Walker <darylew_at_[hidden]> on Mon, 28 May 2001 13:41
>Someone has already done it. There are two implementations in the vault, in
>the IOGlue package and in my more_io package.

I tried the icstream class in more_io however it does not seem to
support streams (no seek?)

The following code performs identically:

int pipe_out[2];
pipe(pipe_out);

...

FILE* outstream = fdopen(pipe_out[0], "r");
FILE* outstreama = fopen("./extr","r");

char temp[512];
while(fscanf(outstream,"%s", temp) != EOF)
  std::cerr << "Got ["<< temp << "]" << std::endl;
while(fscanf(outstreama,"%s", temp) != EOF)
  std::cerr << "Got ["<< temp << "]" << std::endl;

I get identical output.

However, with:

int pipe_out[2];
pipe(pipe_out);

...

FILE* outstream = fdopen(pipe_out[0], "r");
FILE* outstreama = fopen("./extr","r");

boost::icstream results(outstream);
boost::icstream resultsa(outstreama);

std::string tempa;

while(results>>tempa) {
  std::cerr << "aGot [" << tempa << "]" << std::endl;
}
while(resultsa>>tempa) {
  std::cerr << "bGot [" << tempa << "]" << std::endl;
}

I only get data from resultsa.

I am using gcc 3.1 branch (20010511 snapshot) on Solaris 2.8. With
gcc 2.95.3, it doesn't even come close to building because of the
missing headers.

Also it has identical behavior with SUNWspro6.0. (after removing the
inlines on the constructors)

Any suggestions?

Joel
jdy_at_[hidden]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk