Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

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

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


Previous fileTop of DocumentContentsIndexNext file

©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.