Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library User's Guide

41.3 Creating and Using Streams Instantiated on User-Defined Types

Once all the support work is finished, you can instantiate a stream class template on your type and begin to use it--well, not quite. Because the new stream requires the new facets you've defined, you must first create a new locale containing these facets and then imbue that locale on your stream. You can do this as follows:

//1Typedef the special stream type to something convenient.
//2Construct a new locale object and replace the std::codecvt and std::ctype facets with the ones we've defined for Echar. We use the constructor that takes an existing locale and a new facet to construct a locale with a new codecvt facet, and then use it again to get a locale with both new facets.
//3Construct an Estream.
//4Imbue the new locale object containing our replacement facets onto the Estream.

Now we're ready to insert Echars into the stream and read them back in:

//1Get current position.
//2Write out the integer 10.
//3Seek back.
//4Read in the string 10 as Echars.

Previous fileTop of DocumentContentsIndex pageNext file