Stream objects

x::fd references provide three methods that associate an std stream object with the file descriptor: getistream(), getostream(), and getiostream(). They return an x::istream, x::ostream, x::iostream references, accordingly. These references point to an object that's derived from its namesake in the std namespace, and x::obj. There are no equivalent for wide-character streams. LIBCXX implements wide character support differently. The C++ library implements conversion between narrow and wide characters in the stream buffer. LIBCXX uses the IO filters framework to handle wide character conversion as a separate layer. Note that because x::istream, x::ostream and x::iostream are references, use the * operator where the context calls for a std stream:

#include <x/fd.H>

x::fd outputFile(x::fd::create("outputfile.dat"));

x::ostream outputFileStream(outputFile->getostream());

(*outputFileStream) << std::setw(10) << "Title" << std::endl << std::flush;

Output stream objects require more explicit flushing than their std counterparts. They maintain an internal stream buffer object. Since it's a reference-counted object, it gets destroyed automatically when the last reference to the underlying object goes out of scope. Anything that was still buffered by the underlying stream buffer object gets lost, and not flushed to the underlying file descriptor.

By default, these stream buffers are initialized by default with exceptions() set to std::ios::badbit, so that exceptions thrown from the underlying file descriptor objects get propagated by std::{i|i|io}stream.