Tools.h++ Manual

104011 Tandem Computers Incorporated 21-229
21
Example The example that follows is a “writer” program that encodes an XDR structure
onto a FILE stream. The example for class
RWXDRistream
is the “reader”
program that decodes the XDR structures into a machine representation for a
data type. The library that supports XDR routines must be linked in. The name
of this library is not standard.
Public constructors
RWXDRostream(XDR* xp);
Initialize an
RWXDRostream
from the XDR structure xp.
Public member functions
virtual RWvostream& operator<<(const char* s);
Redefined from class
RWvostream
. Store the character string starting at
s
to
the output stream using the XDR format. The character string is expected to be
null terminated.
virtual RWvostream& operator<<(char c);
Redefined from class
RWvostream
. Store the character
c
to the output stream
using the XDR format. Note that
c
is treated as a character, not a number.
virtual RWvostream& operator<<(wchar_t wc);
Redefined from class
RWvostream
. Store the wide character
wc
to the output
stream using the XDR format. Note that wc is treated as a character, not a
number.
#include “rw/xdrstrea.h”
#include “rw/rstream.h”
#include <stdio.h>
main()
{
XDR xdr;
FILE* fp = fopen(“test”,”w+”);
xdrstdio_create(&xdr, fp, XDR_ENCODE);
RWXDRostream rw_xdr(&xdr);
for(int i=0; i<10; ++i)
rw_xdr << i;// encode integer data
fclose(fp);
}