Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Tools Module User's Guide

5.4 Simple Example

Here is a simple example that exercises RWbostream and RWbistream through their respective abstract base classes, RWvostream and RWvistream:

Program Output:

The job of function save(const RWCString& a, RWvostream& v) is to save the string a to the virtual output stream v. Function recover(RWvistream&) restores the results. These functions do not know the ultimate format with which the string will be stored. Here are some additional comments on particular lines:

//1 On this line, a file output stream f is created for the file junk.dat.
//2 An RWbostream is created from f.
//3 Because this clause is enclosed in braces { ... }, the destructor for f will be called here. This will cause the file to be closed.
//4 The file is reopened, this time for input.
//5 Now an RWbistream is created from it.
//6 The string is recovered from the file.
//7 Finally, both the original and recovered strings are printed for comparison.

You could simplify this program by using class fstream, which multiply inherits ofstream and ifstream, for both output and input. A seek to beginning-of-file would occur before reading the results back in. Since some early implementations of seekg() have not proven reliable, we chose not to use the simpler approach for this example.

Previous fileTop of DocumentContentsIndex pageNext file

©2004 Copyright Quovadx, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.