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:

//1 Typedef the special stream type to something convenient.
//2 Construct 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.
//3 Construct an Estream.
//4 Imbue 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:

    Echar e[10];
    Estream::pos_type pos = foo.tellp(); //1
    foo << 10; //2
    foo.seekg(pos); //3
    foo >> e; //4
    
//1 Get current position.
//2 Write out the integer 10.
//3 Seek back.
//4 Read in the string 10 as Echars.

Previous fileTop of DocumentContentsIndex pageNext file

AltStyle によって変換されたページ (->オリジナル) /