test.cc
Upload User: shengde
Upload Date: 2021-02-21
Package Size: 638k
Code Size: 1k
Development Platform:

Visual C++

  1. /*
  2.  * Test program for gzifstream and gzofstream
  3.  *
  4.  * by Ludwig Schwardt <schwardt@sun.ac.za>
  5.  * original version by Kevin Ruland <kevin@rodin.wustl.edu>
  6.  */
  7. #include "zfstream.h"
  8. #include <iostream>      // for cout
  9. int main() {
  10.   gzofstream outf;
  11.   gzifstream inf;
  12.   char buf[80];
  13.   outf.open("test1.txt.gz");
  14.   outf << "The quick brown fox sidestepped the lazy caninen"
  15.        << 1.3 << "nPlan " << 9 << std::endl;
  16.   outf.close();
  17.   std::cout << "Wrote the following message to 'test1.txt.gz' (check with zcat or zless):n"
  18.             << "The quick brown fox sidestepped the lazy caninen"
  19.             << 1.3 << "nPlan " << 9 << std::endl;
  20.   std::cout << "nReading 'test1.txt.gz' (buffered) produces:n";
  21.   inf.open("test1.txt.gz");
  22.   while (inf.getline(buf,80,'n')) {
  23.     std::cout << buf << "t(" << inf.rdbuf()->in_avail() << " chars left in buffer)n";
  24.   }
  25.   inf.close();
  26.   outf.rdbuf()->pubsetbuf(0,0);
  27.   outf.open("test2.txt.gz");
  28.   outf << setcompression(Z_NO_COMPRESSION)
  29.        << "The quick brown fox sidestepped the lazy caninen"
  30.        << 1.3 << "nPlan " << 9 << std::endl;
  31.   outf.close();
  32.   std::cout << "nWrote the same message to 'test2.txt.gz' in uncompressed form";
  33.   std::cout << "nReading 'test2.txt.gz' (unbuffered) produces:n";
  34.   inf.rdbuf()->pubsetbuf(0,0);
  35.   inf.open("test2.txt.gz");
  36.   while (inf.getline(buf,80,'n')) {
  37.     std::cout << buf << "t(" << inf.rdbuf()->in_avail() << " chars left in buffer)n";
  38.   }
  39.   inf.close();
  40.   return 0;
  41. }