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.
Example 5 shows how to use the 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. |
Example 6 shows how to use the 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. |
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.