return type of boost::iostreams::stream<T>::read()

I apologize, if i have missed something.

Reading the documentation about boost::iostreams library I could not find the 
information which return type the boost::iostreams::stream's class is giving 
me calling read(). I searched through the headers and every read() found 
returns std::streamsize, which sounds reasonable to me.

I was surprised, that the code below does not compile
--------start code ----------
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/device/file.hpp>

int main(void){
  boost::iostreams::stream<boost::iostreams::file_source>
	istr(std::string("in.pdf"));
  char *buffer = new char[10];
  std::streamsize i = istr.read(buffer,10);
  return 0;
}
-------end code-----------

and gives me:
test.cpp:7: error: invalid conversion from ‘void*’ to ‘std::streamsize’

Could someone shed a light on me, please?

Thanks in advance.

kind regards
Axel
(Continue reading)

Eric MALENFANT | 14 Oct 15:47

Re: return type of boost::iostreams::stream<T>::read()

Struebing, Axel, le-tex [axel.struebing <at> le-tex.de]:
> Reading the documentation about boost::iostreams library I could not
> find the information which return type the boost::iostreams::stream's
> class is giving me calling read().

>From the documentation, a boost::iostreams::stream derives from an std::basic_[i|o]stream,
depending on the model of its underlying Device. In your example, the device is a Source, so I guess that the
stream derives from std::basic_istream, whose read(char*, streamsize) method returns a
basic_istream, not a streamsize.

The library offers the "streamsize read(stream, char*, streamsize)" function template. Using it in your
example yould give something like (not tested):

  #include <boost/iostreams/stream.hpp>
  #include <boost/iostreams/device/file.hpp>
  #include <boost/iostreams/operations.hpp>  

  int main(void){
    namespace bio = boost::iostreams;
    bio::stream<bio::file_source> istr(std::string("in.pdf"));
    char buffer[10];
    std::streamsize i = bio::read(istr,buffer,10);
    return 0;
  }

 
HTH,

Éric Malenfant
---------------------------------------------
(Continue reading)

Re: return type of boost::iostreams::stream<T>::read()

Hallo Éric,

although it is not an exact fit it will be of value in evaluating my options.

kind regards
Axel Strübing

> > Reading the documentation about boost::iostreams library I could not
> > find the information which return type the boost::iostreams::stream's
> > class is giving me calling read().
> >
> >From the documentation, a boost::iostreams::stream derives from an
> > std::basic_[i|o]stream, depending on the model of its underlying Device.
> > In your example, the device is a Source, so I guess that the stream
> > derives from std::basic_istream, whose read(char*, streamsize) method
> > returns a basic_istream, not a streamsize.
>
> The library offers the "streamsize read(stream, char*, streamsize)"
> function template. Using it in your example yould give something like (not
> tested):
>
>   #include <boost/iostreams/stream.hpp>
>   #include <boost/iostreams/device/file.hpp>
>   #include <boost/iostreams/operations.hpp>
>
>   int main(void){
>     namespace bio = boost::iostreams;
>     bio::stream<bio::file_source> istr(std::string("in.pdf"));
>     char buffer[10];
>     std::streamsize i = bio::read(istr,buffer,10);
(Continue reading)

Re: return type of boost::iostreams::stream<T>::read()

okay, it's within my grasp now. 
Primarily I get a basic_istream. To facilitate the 'while std::cin' idiom, 
there is a conversion of basic_istream to void* defined. 

That seems to hit me in my example.

FYI: std::streamsize i = istr.read(buffer,10); 
is calling the read-function of my DeviceT template parameter, perfect. So I 
am probably going to use a read + gcount-combination.

Thanks again 
Axel

> Hallo Éric,
>
> although it is not an exact fit it will be of value in evaluating my
> options.
>
> kind regards
> Axel Strübing
>
> > > Reading the documentation about boost::iostreams library I could not
> > > find the information which return type the boost::iostreams::stream's
> > > class is giving me calling read().
> > >
> > >From the documentation, a boost::iostreams::stream derives from an
> > > std::basic_[i|o]stream, depending on the model of its underlying
> > > Device. In your example, the device is a Source, so I guess that the
> > > stream derives from std::basic_istream, whose read(char*, streamsize)
> > > method returns a basic_istream, not a streamsize.
(Continue reading)


Gmane