[iostreams] Assertion in detail/optional.hpp, line 54

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; class IOutput { public: virtual void print(int, const char*) const = 0; }; class Output : public IOutput { public: void print(int id, const char* a) const { cout << a; } }; static IOutput* gpOutput; 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; return 0; } When I compile in release mode the program prints `Daniel', just as expected. Is there a problem with my program? Thanks in advance! Hälsningar, Daniel

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
participants (2)
-
Daniel Lidström
-
Jonathan Turkanis