Boost logo

Boost :

From: Brian Braatz (brianb_at_[hidden])
Date: 2005-02-28 18:38:48


In working with the code below, I just moved it to VC70. The iostreams
docs point me to not officially supporting vc71, but they do say some of
the support has been left in.

While trying to compile below, I got caught up with a static assert, I
noticed the

#ifndef BOOST_IOSTREAMS_NO_FULL_SMART_ADAPTER_SUPPORT

Was around the static assert. So being a gambling sorta guy, I #defined
BOOST_IOSTREAMS_NO_FULL_SMART_ADAPTER_SUPPORT and that got rid of that
static assert.

I am now having issues with detail::resolve_traits

// Deduces the return type of resolve.
template<typename Mode, typename Ch, typename T>
struct resolve_traits {
    BOOST_STATIC_ASSERT(!is_const<T>::value);

I have been digging through trying to figure this one out. I have not
yet.

My Question- is there a workaround that allows for minimal \ limited
useage of iostreams with VC70. (I have a project I am working on code
for that is STUCK on that compiler)..

The code below is what I am trying to make work.

Many Thanks,

Brian

-----Original Message-----
From: Brian Braatz
Sent: Monday, February 28, 2005 1:54 PM
To: 'boost_at_[hidden]'
Subject: Iostreams Question: Best way to output to win32
debugger\outwindow ?

First off THANK YOU Johnathon Turkanis for help with "tee" earlier. That
saved me a great amount of pain.

Below is part of what I am trying to use it with.

My next question is what is the best way to deal with an "output" device
having a different cr\lf than another one?

My basic problem is this-

I want to be able to take

cout << "hi" << endl << "there" << endl;

and have it properly give an end of line for the MSVC debugger (the same
issue exists with the windows edit control)

the problem is with both the windows edit control and the MSVC debug out
window, you need to give it a \r\n instead of just a \n

As you will see in my code below, there is "stupidity" (i.e. look for
the memcpy :) )

My question is this- What is your suggested way to do what I am trying
to do.
(code below DOES work)

using namespace std;
using namespace boost::io;

    struct tee : boost::io::multichar_output_filter
    {
        tee(std::ostream& dest) : dest(dest) { }

        template<typename Sink>
        void write(Sink& snk, const char* s, std::streamsize n)
        {
            // Write to the downstream Sink
            boost::io::write(snk, s, n);

            // Write to the stored ostream:
            dest.write(s, n);
        }

        std::ostream& dest;
    };

    struct debug_out_sink : public sink
    {
        debug_out_sink()
        { }
       void write( const char* s, std::streamsize n)
        {
            // copy the incoming data into a new location so we can NULL
terminate
            char * sout = new char[(n+1)*2];
            memcpy(sout,(void*)s,n);
            sout[n] = 0;
            // make a std::string from null terminated string
            std::string ssOut = sout;
            
            // replace all occurances of \n with \r\n
            // this is the end of line sequence used for the win32
debugger
            // (this is also for edit controls on the windows platform)
            boost::replace_all(ssOut,"\n","\r\n");
            OutputDebugString(ssOut.c_str());
            
            // clean up
            delete [] sout;
            sout = NULL;
        }
    };
       
        void Test_Profile()
        {
        using namespace boost::io;
        filtering_ostream out;
        std::ofstream log("log.txt");
        debug_out_sink dbosink;
        out.push(tee(log));
        out.push(tee(std::cout));
        out.push(dbosink);
        
        out <<"LINE ONE" << endl << "Next line" << endl << "third line"
<< endl;
    }


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