boost::iostreams output filter doesn't work
Hi all, I desire to use boost::iostream input and output filters. I cannot make the "Filter Usage Examples" (para2.2.2) shown here () to work. the following, as far as I can tell, is exactly the same "Ordinary OutputFilter" example shown at (http://tinyurl.com/45bur3o) struct toupper_filter { typedef char char_type; typedef boost::iostreams::output_filter_tag category; template<typename Sink> bool put(Sink& snk, char c) { return boost::iostreams::put(snk, toupper((unsigned char) c)); } }; the following code is modeled on the code at para2.2.2, "Filter Usage Examples": int main(int argc, char *argv[]) { // read my_input.txt and save uppercase version of text into datastore.txt std::ifstream pt_input; pt_input.open("my_input.txt"); std::ostringstream oss; oss << pt_input.rdbuf(); // oss now contains the text stored in input text boost::iostreams::filtering_ostream out_stream; // the following line is expected to transform the input text to uppercase. // instead it causes no text to appear in the output file. If the following line of // code is commented-out then contents of "my_input.txt" is placed in "datastore.txt". out_stream.push(toupper_filter()); out_stream.push(boost::iostreams::file_sink("datastore.txt")); out_stream.write( oss.str().c_str(), oss.str().length()); out_stream.flush(); } I am obviously doing not adding the toupper_filter into the filter chain correctly. Can anyone point out what I am doing wrong? many thanks
On 2/8/2011 1:22 PM, John Hendrix wrote:
Hi all,
the following, as far as I can tell, is exactly the same "Ordinary OutputFilter" example shown at (http://tinyurl.com/45bur3o)
...
I am obviously doing not adding the toupper_filter into the filter chain correctly. Can anyone point out what I am doing wrong?
Not sure what you are doing... but your code works for me on Windows with VS2008 using Boost 1.45. My_input.txt contained 1 line as follows: ThIs Is A tEsT 123! After running, datastore.txt contained: THIS IS A TEST 123! What version of boost, what compiler, what input and output do you get?
OK, I found it. Short answer: for some reason running this code from within the context of a Qt console app breaks it. Now let me respond to your questions: I using VC 2008 with boost 1.44. I am also compiling from within the Qt environment. I did not show all of the code because it wouldn't compile unless you were working with qt. The real code looked like: int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); // read my_input.txt and save uppercase version of text into datastore.txt // code shown in previous email redacted return a.exec(); } Commenting-out the line with QCoreApplication and replacing the return statement with "return 0" made it work. I don't yet understand the problem but at least I now know that both the example works and I didn't bungle it. Many thanks for taking the time to look at my problem. johnh On Thu, Feb 10, 2011 at 6:48 PM, eg <egoots@gmail.com> wrote:
On 2/8/2011 1:22 PM, John Hendrix wrote:
Hi all,
the following, as far as I can tell, is exactly the same "Ordinary
OutputFilter" example shown at (http://tinyurl.com/45bur3o)
...
I am obviously doing not adding the toupper_filter into the filter chain correctly. Can anyone point out what I am doing wrong?
Not sure what you are doing... but your code works for me on Windows with VS2008 using Boost 1.45.
My_input.txt contained 1 line as follows: ThIs Is A tEsT 123!
After running, datastore.txt contained: THIS IS A TEST 123!
What version of boost, what compiler, what input and output do you get?
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Join us at at Tampa Bay's largest Tax Day Tea Party: www.TaxDayTampaBay.com Revolution is Brewing--America Rising www.Tampa-Tea-Party.com
participants (2)
-
eg
-
John Hendrix