home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_08_03
/
8n03052a
< prev
next >
Wrap
Text File
|
1990-03-20
|
928b
|
51 lines
*****Listing 4*****
// a buffer is a kind of yacht of characters, which can optionally be
// associated with a File
class Buffer : public Yacht {
public:
Buffer() : () {} // constructor for buffers not connected to a file
Buffer( char *filename) : ()
{
if( filename == 0 )
;
else if( read( filename) )
;
else
error( "could not open %s\n", filename);
begin();
}
Truth read( char *filename)
{
int r = 1;
if( filename ) {
File f( filename);
if( f.isok() ) {
for( ; !f.iseof(); next() )
putb( f.get() );
} else r = 0;
}
return r;
}
Truth write( char *filename)
{
int r = 1;
if( filename ) {
File f( filename, "w");
if( f.isok() ) {
for( ; !isend(); next() )
f.put( geta() );
} else r = 0;
}
return r;
}
private:
void error( char *msg, char *arg) { printf( msg, arg); }
};