Boost logo

Boost Users :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2005-11-18 14:36:53


Daniel Lidström wrote:
> Hello!
>
> when compiled in debug mode, the following program causes an exception
> in the file p:\boost_1_33_0\include\boost-1_33\boost\iostreams\detail\
> optional.hpp, line 54 (I'm using VC 7.1.3088, Windows XP):
>
> #include <iostream>
> #include <boost/iostreams/concepts.hpp> // sink
> #include <boost/iostreams/stream.hpp> // stream
>
> using namespace std;

<snip>

> template<int id>
> class my_sink : public boost::iostreams::sink
> {
> public:
>
> std::streamsize write(const char* s, std::streamsize n)
> {
> gpOutput->print(id, s);
> std::streamsize sz = 0;
> for( const char* p=s; *p; ++p ) sz++;
> return sz;
> }
> };
>
> typedef boost::iostreams::stream<my_sink<5> > output;
>
> int main()
> {
> gpOutput = new Output;
>
> output stream;
>
> stream << "Daniel" << endl;

Here's the problem: you're writing to a stream without opening it. Try:

     output stream;
     stream.open(my_sink());
     stream << "Daniel" << endl;

> return 0;
> }

> Hälsningar,
> Daniel

-- 
Jonathan Turkanis
www.kangaroologic.com

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