How to convert OutputStream into MemoryOutputStream?

How to convert OutputStream into the MemoryOutputStream.

I tried dynamic_cast as shown below  but thats not working.

const OutputStream &  stream

MemoryOutputStream * memStream = dynamic_cast<MemoryOutputStream*>(&stream);

How to convert OutputStream into the MemoryOutputStream.

MemoryOutputStream is already an OutputStream. In other words, MemoryOutputStream inherits from it's base class, which is OutputStream. By using a MemoryOutputStream, all of the functions in OutputStream are available to you.

What are you trying to do?

Problem solved. I just need to remove const from const OutputStream & stream; i can't use dynamic cat to convert const type into non const type. Thanks for your reply