views:

87

answers:

1

Is it possible to tie a C++ output stream to another output stream?

I'm asking because I've written an ISAPI extension in C++ and I've written ostreams around the WriteClient and ServerSupportFunction/HSE_REQ_SEND_RESPONSE_HEADER_EX functions - one ostream for the HTTP headers and one for the body of the HTTP response. I'd like to tie the streams together so that all the HTTP headers are sent before the rest of the response is sent.

+4  A: 

Yes, you can:

out1.tie( & out2 );

where both outs are output streams. out2 will be flushed before output to out1.

anon
@Neil: what are "streans"? I edited your answer with a fix to "streams" but you've edited it back to "streans". So I guess I'm missing something (English is my 3rd language, so sorry in advance)
Eli Bendersky
@Eli, his edit (addendum) just clashed with yours. I've fixed it to streams again.
Johannes Schaub - litb
@Eli No, you are right - I made an unrelated change at what must have been exactly the same time as yours. Thanks.
anon
@Neil, litb: seems like the comment engine of SO isn't transactional ;-)
Eli Bendersky
Thanks! All the documentation talked about tying input to output streams so I wasn't sure if output-to-output would work.
Emanuel