As long as you have a way it doesn't get destroyed after scope.
LOL, yes it does. Allocators aren't magical. They can't count language references, only references in the objects they are aware of. All objects created in the stack are destructed when their frame expires (i.e. when the control flow moves out of the block they were created in).
It is possible, however, to return a pointer to dynamically allocated stream.
I have no clue what you just said helios.... [...] This is what I mean. You can allocate memory dynamically and then send a pointer or reference as a return statement. How is this magical?
Can't you return a reference to the stream?
You're kinda mixing things up, there. First, it's obviously not the same to return a pointer or a reference; second, you can't return a reference to a dynamic object.