Tools.h++ Class Reference

Table Of Contents
// just for fun, print out some statistics:
cout << "We just saved " << crcb
<< " bytes of data to the file." << endl;
cout << "The checksum for those bytes was " <<check << endl;
} // end of block
// now read the data back in, checking to see if it survived.
unsigned char check = '\0';
// create an instream
ifstream ip("crc.pst");
// create an RWAuditStreamBuffer that will do CRC
RWAuditStreamBuffer crcb(ip,doCrc,&check);
// create an RWpistream to interpret the bytes
RWpistream p(&crcb);
RWCString first, mid1, mid2;
int value;
double pi;
char pnc;
unsigned int savedCRC;
unsigned char matchCRC;
// read in the data. Don\'t read the checksum yet!
p >> first >> value >> mid1 >> mid2 >> pi >> pnc;
// save the checksum
matchCRC = check;
// Now it is safe to alter the running checksum by reading in
// the one saved in the file.
p >> savedCRC;
if(savedCRC != matchCRC) {
cout << "Checksum error. Saved CRC: " << savedCRC
<< " built CRC: " << matchCRC << dec << endl;
}
else {
cout << "The message was: " << endl;
cout << first << value << mid1 << mid2 << pi << pnc << endl;
}
// just for fun, print out some statistics:
cout << "We just read " << crcb
<< " bytes of data from the file." << endl;
cout << "The checksum was " << matchCRC << flush;