Simple example – HP Integrity NonStop J-Series User Manual
Page 77

Click on the banner to return to the user guide home page.
©Copyright 1996 Rogue Wave Software
Simple Example
Here's a simple example that exercises
RWbostream
and
RWbistream
through their respective
abstract base classes,
RWvostream
and
RWvistream
:
#include
#include
#include
#ifdef __BORLANDC__
# define MODE ios::binary // 1
#else
# define MODE 0
#endif
void save(const RWCString& a, RWvostream& v){
v << a; // Save to the virtual output stream
}
RWCString recover(RWvistream& v) {
RWCString dupe;
v >> dupe; // Restore from the virtual input stream
return dupe;
}
main(){
RWCString a("A string with\ttabs and a\nnewline.");
{
ofstream f("junk.dat", ios::out|MODE); // 2
RWbostream bostr(f); // 3
save(a, bostr);
} // 4
ifstream f("junk.dat", ios::in|MODE); // 5
RWbistream bistr(f); // 6