The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Concatenate streams in C++

I am using C++.  I have a stream that comes from a socket.  I want to create a new stream which concatenates the socket stream to a pre-existing stream.

Is there a standard method of doing this in C++?

Tuesday, May 01, 2007
I guess you might as well just repeatedly extract from the input stream and insert into the output stream until the input stream runs out. As I recall, if the stream is binary, you can just extract and insert chars and get the result you expect. Doesn't get much simpler than that.

(For a more "standard" approach, you're probably supposed to use ostream_iterator and istream_iterator, maybe in conjunction with std::copy. But since there's no such thing as an "end" for the "sequence" implied by the istream_iterator, you can't do this...)
Tuesday, May 01, 2007

Tuesday, May 01, 2007
I think the OP has solved his problem now but for information, it is possible to create an end iterator for istream_iterator : it is the default constructor.

std::istream_iterator itBegin(istreamSource);
std::istream_iterator itEnd;
std::ostream_iterator itOutput(ostreamDestination);

std::copy(itBegin, itEnd, itOutput);
Vincent Robert Send private email
Monday, May 07, 2007

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz