A fun filled journey into the Standard Library's dark continent, illuminating the mysteries of IOStreams and revealing the streambufs beneath.
C++ IOStreams - what they do, how they work, why you might want to write your own, and how to do it without pain or fuss.
IOStreams is one of the lesser known areas of the standard library. While most people are now entirely comfortable slinging around std::vectors and std::lists, and know the difference between a std::map and a std::set, IOStreams is still rather opaque.
Sure, writing an operator<< isn't too big a deal, and maybe the bold have even come up with a custom manipulator. But streams? Where do they come from? Where do they go?
In a fun filled journey into the Standard Library's dark continent, we will attempt to illuminate the mysteries of IOStreams and reveal the streambufs beneath.
Starting with a quick tour through IOStreams excitingly diamond shaped class hierarchy, we'll introduce the concepts of sources and sinks (i.e. Streams which read from or write to some external destination) and filters/adaptors (streams that modify data in flight). We'll also talk about some of IOStreams little idiosyncrasies – why some buffers might not actually buffer, and why read-only buffers sometimes need to be writable.
By way of illustration we'll be walking through a logging stream. It writes log messages to an arbitrary number of other streams. The destination streams will be a combination of fstreams, stacks of filters, logging daemons on other machines, and whatever else we need.