Essential Networking Module User’s Guide : PART II The Networking Package : Chapter 5 Streams
Chapter 5 Streams
Using Iostreams
C++ uses iostreams as the standard mechanism for input and output. Iostreams allow type-safe insertion and extraction of both user-defined and built-in types into and out of communication streams. The Networking package iostreams classes enable you to use the standard iostreams classes for input and output, using a portal as the underlying source and sink of bytes.
Using Iostream Classes for Formatted Output
Example 5 shows how to use the iostream classes for formatted output into a portal.
Example 5 – Using iostream classes for formatted output into a portal
// set up the RWPortal object, portal
 
RWPortalOStream ostrm(portal); //1
ostrm << "hello world" << endl; //2
//1 Sets up an ostream object, which uses the RWPortal object portal for its sink of bytes. The RWPortalOStream makes its own copy of the portal, which enables you to specify a temporary object in the constructor.
//2 Outputs objects using the stream. Because the RWPortalOStream class is derived from ostream, any objects that can be inserted into an ostream can also be inserted into an RWPortalOStream.
Using Iostream Classes for Formatted Input
Example 6 shows how to use the iostream classes for formatted input.
Example 6 – Using iostream classes for formatted input
// set up the RWPortal object, portal
 
RWPortalIStream istrm(portal); //1
RWCString s;
istrm >> s; //2
//1 Sets up an istream object that uses the RWPortal object portal for its source of bytes. The RWPortalIStream also makes its own copy of the portal, which enables you to specify a temporary object in the constructor.
//2 Inputs objects using the stream. Because the RWPortalIStream class is derived from istream, any objects that can be extracted from an istream can also be extracted from an RWPortalIStream.