Boost logo

Boost :

Subject: Re: [boost] Standard stream from C fopen()
From: Eric MALENFANT (Eric.Malenfant_at_[hidden])
Date: 2010-11-12 14:08:14

De :Claude
> I Use this code for make a standard stream from a C fopen() FILE* :
> FILE *fd = fopen("Prova", "w");
> if (fd)
> {
> // io::stream_buffer<io::file_descriptor_source> fpstream
> (fileno(fd));
> //std::istream in (&fpstream);
> istream in = boost::iostreams::file_descriptor(fileno(fd));
> }
> But I obtain an error (G++ on Linux Ubuntu):

file_descriptor is a "Device", not a "stream". To make a stream out of a Device, wrap the latter into a stream. From the description of stream in the docs:

Stream template which performs i/o by delegating to a contained Device. The Device type is specified as the first template parameter to stream. Instances of the the Device type are attached and detached using the member functions open and close.

The template stream derives from a specialization of std::basic_istream, std::basic_ostream or std::basic_iostream, depending on whether the underlying Device models Source, Sink or both..

Note: I believe this question would be more suited for the "users" mailing list

Boost list run by bdawes at, gregod at, cpdaniel at, john at