Implementing binary output to a file in C++11
I would not write an adapter for a stream.
But rather a stream manipulator.

Try this:

#include &lt;ostream&gt;

// The object that does all the work.
class BBoolWrapper
{
    std::ostream&amp;          str;
    mutable std::size_t    position;
    mutable std::bitset&lt;sizeof(unsigned long) * CHAR_BIT&gt; data;

    public:
        BBoolWrapper(std::ostream&amp; str)
            : str(str)
            , position(0)
        {}
        ~BBoolWrapper()
        {
            // If there is data to be flushed when we destroy the
            // object then make sure it goes on the stream.
            flush();
        }

        // Testing state.
        bool empty() const      { return position == 0;}
        bool full() const       { return position == data.size();}

        // Just the way I do it.
        // You can add bits any way you like one at a time.
        void addBit(bool nextbit) const
        {
            data &lt;&lt;= 1;
            data[0] = nextbit;
            ++position;
            if (full())
            {
                flush();
            }
        }

        // Simple Flush to the stream (if there is any data).
        void flush() const
        {
            if (!empty())
            {
                unsigned long value = data.to_ulong();
                str.write(reinterpret_cast&lt;char*&gt;(&amp;value), sizeof(unsigned long));
                position  = 0;
            }
        }

    // The interesting part.
    // If we have an object like this and a bool using the `&lt;&lt;` operator
    // Then add the bit and return this object so we are chaining the
    // `&lt;&lt;` operations.
    friend BBoolWrapper const&amp; operator&lt;&lt;(BBoolWrapper const&amp; stream, bool nextbit)
    {
        stream.addBit(nextbit);
        return stream;
    }

    // If we use any other type with `&lt;&lt;` operator then flush this object.
    // Return the underlying stream object to get back to normal stream
    // operations.
    template&lt;typename T&gt;
    friend std::ostream&amp; operator&lt;&lt;(BBoolWrapper const&amp; stream, T const&amp; val)
    {
        stream.flush();
        return stream.str &lt;&lt; val;
    }
};

// A simple empty class to start the streaming of bits
// via the above wrapper class.
struct BBool
{
    friend BBoolWrapper operator&lt;&lt;(std::ostream&amp; stream, BBool const&amp;)
    {
        return BBoolWrapper(stream);
    }
};


Example:

#include &lt;iostream&gt;
#include &lt;ifstream&gt;

int main()
{

    // Use the BBool() object on a stream to turn binary mode on.
    // It stays on until you add a non boolean object to the chain. (like "\n")
    std::ofstream log("log");
    log       &lt;&lt; BBool() &lt;&lt; false &lt;&lt; true &lt;&lt; false &lt;&lt; false &lt;&lt; false &lt;&lt; false &lt;&lt; false &lt;&lt; true &lt;&lt; "\n";
    std::cout &lt;&lt; BBool() &lt;&lt; false &lt;&lt; true &lt;&lt; false &lt;&lt; false &lt;&lt; false &lt;&lt; false &lt;&lt; false &lt;&lt; true &lt;&lt; "\n";
}