Subject: [boost] [iostreams] output_filter works only once
From: Steven Samuel Cole (steven.samuel.cole_at_[hidden])
Date: 2012-02-13 01:30:31
i am trying to use an boost::iostreams output filter to add a string to
the beginning and the end of whatever i stream out.
my code below works, but only the first time; the second time, the
output seems to get lost somewhere, the write method doesn't even seem
to get called. i thought at first i'm sending something to the stream
that triggers its fail bit, but the stream seems good.
the same problem occurs on mac and linux, with latest boost release
(1.48) and svn trunk, with cout and a file sink as device.
is that a bug ? or am i doing something wrong in my code ?
: public boost::iostreams::multichar_output_filter
streamsize write(Sink& sink, const char* s, streamsize n)
string out_string = string(s);
// remove trailing '\0' to prevent line break
if (out_string[out_string.size()-1] = '\0')
out_string = out_string.substr(0, out_string.size()-1);
string pre_string("prepended string - ");
string app_string(" - appended string");
sstrm << pre_string << out_string << app_string << endl;
// TODO: char* to string, back to char* ?!?
// string #01 is printed,
// string #02 gets lost
out << "string #01" << endl;
out << "string #02" << endl;