Boost logo

Boost :

From: Dirk Griffioen (dirkgriffioen_at_[hidden])
Date: 2005-03-22 05:10:39


Hi,

 

I would love to use the boost::iostreams lib, so I created a filter
(which, in this case, does encryption)

but instead of passing it std::cout I would like to pass it some other
stream, a stringstream for instance (or any kind of ostream/istream,
depending on the direction).

 

However, I was very surprised to find the following code taking 100% cpu
and not returning. It probably means I did something wrong, but I can't
seem to find it.

 

void test_encryption_filter()

 {

    const char* speech =

        "They sorely misunderestimate the American people if they "

        "think we will let them obtain nucular weapons. This "

        "malfeance will not stand.";

 

    // std::ostream which writes to standard output, filtered by a

    // encryption_output_filter.

    boost::io::filtering_ostream out;

    out.push(encryption::code_book::output_filter());

 

    //out.push(std:cout); //this works

 

    std::ostringstream os;

    out.push(os); //this does not

 

    // Print unfiltered code.

    std::cout << "**** Speech unfiltered ****\n" << speech << "\n\n";

  

    // Print filtered code:

    std::cout << "**** Speech with encryption filter ****\n";

    out << speech << "\n\n";

}

 

(testing puspose) filter looks like (namespace omitted):

 

struct output_filter : public multichar_output_filter {
        template<typename Sink>
        void write(Sink& snk, const char* s, streamsize n)
            {
                while (n-- > 0)
                    boost::io::put(snk, toupper(*s++));
            }
    };

 

 

With std::cout this works fine, with std::ostringstream it does not.

 

So could anyone please tell me what I am missing?

 

Thanks in advance, Dirk

**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed.

If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited.

If you have received this email in error please notify
our system management at postmaster_at_[hidden] and immediately and permanently delete this message and any attachments.

********************************************


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk