Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Math Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

7.2 A Simple Example Using Streams

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

Program output:

The job of function save(RWMathVec<T>& a, RWvostream& v) is to save the vector a to the virtual output stream v. Function recover(RWvistream&) restores the results. These functions do not know the ultimate format with which the vector will be stored, although in this case it will be in binary format because the specializing classes are RWbostream and RWbistream. 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

On this line, an RWbostream is created from f.

//3

Because this clause is enclosed in braces { ... }, the destructor for f is called here. This causes the file to be closed.

//4

The file is reopened, this time for input.

//5

Now an RWbistream is created from it.

//6

The vector is recovered from the file.

//7

Finally, both the original and recovered vectors are printed for comparison.



Previous fileTop of DocumentContentsNo linkNext file

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.
Provide feedback to Rogue Wave about its documentation.