[iostream]: Simple sinks result in runtime error

Hi all, This is my first post, so please let me know if I am doing anything wrong. 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::streambio::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. Cheers, Marius

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::streambio::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::streambio::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
participants (2)
-
Jonathan Turkanis
-
Marius Renn