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
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