Boost logo

Boost Users :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2005-09-17 03:40:08


Marius Renn wrote:
> Hi all,
> This is my first post, so please let me know if I am doing
> anything wrong.

So far, so good :-)

> I am having trouble using the new iostream headers in Boost
> 3.3. I cannot get simple Sinks to function correctly. Take
> the following code for example:
>
> namespace bio = boost::iostreams;
>
> int main()
> {
> typedef bio::stream<bio::null_sink> nullsink;
>
> nullsink out;
> out << "Ignore me";
> }
>
> This code always results in a runtime assertion failure:
> /usr/local/include/boost/iostreams/detail/optional.hpp:54:
> failed assertion `initialized_'
>
> What am I doing wrong? Any help would be greatly appreciated.

I've made this same mistake. It's the same as if you had written:

   ofstream out;
   out << "hello"; // Whoops! Forgot to open stream

You have to default construct an instance of null_sink and attach
it to the stream. For example:

  bio::stream<bio::null_sink> out;
  out.open(null_sink());
  out << "Ignore me";

You might think that because null_sinks are stateless, you can
skip the second line. But you can't.

> Cheers,
> Marius

Jonathan


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net