home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C18 / Datascan.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  1.9 KB  |  66 lines

  1. //: C18:Datascan.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. //{L} Datalog
  7. // Verify and view logged data
  8. #include "DataLogger.h"
  9. #include "../require.h"
  10. #include <iostream>
  11. #include <fstream>
  12. #include <strstream>
  13. #include <iomanip>
  14. using namespace std;
  15.  
  16. int main() {
  17.   ifstream bindata("data.bin", ios::binary);
  18.   assure(bindata, "data.bin");
  19.   // Create comparison file to verify data.txt:
  20.   ofstream verify("data2.txt");
  21.   assure(verify, "data2.txt");
  22.   DataPoint d;
  23.   while(bindata.read(
  24.     (unsigned char*)&d, sizeof d))
  25.     d.print(verify);
  26.   bindata.clear(); // Reset state to "good"
  27.   // Display user-selected records:
  28.   int recnum = 0;
  29.   // Left-align everything:
  30.   cout.setf(ios::left, ios::adjustfield);
  31.   // Fixed precision of 4 decimal places:
  32.   cout.setf(ios::fixed, ios::floatfield);
  33.   cout.precision(4);
  34.   for(;;) {
  35.     bindata.seekg(recnum* sizeof d, ios::beg);
  36.     cout << "record " << recnum << endl;
  37.     if(bindata.read(
  38.       (unsigned char*)&d, sizeof d)) {
  39.       cout << asctime(&(d.getTime()));
  40.       cout << setw(11) << "Latitude"
  41.            << setw(11) << "Longitude"
  42.            << setw(10) << "Depth"
  43.            << setw(12) << "Temperature"
  44.            << endl;
  45.       // Put a line after the description:
  46.       cout << setfill('-') << setw(43) << '-'
  47.            << setfill(' ') << endl;
  48.       cout << setw(11) << d.getLatitude()
  49.            << setw(11) << d.getLongitude()
  50.            << setw(10) << d.getDepth()
  51.            << setw(12) << d.getTemperature()
  52.            << endl;
  53.     } else {
  54.       cout << "invalid record number" << endl;
  55.       bindata.clear(); // Reset state to "good"
  56.     }
  57.     cout << endl
  58.       << "enter record number, x to quit:";
  59.     char buf[10];
  60.     cin.getline(buf, 10);
  61.     if(buf[0] == 'x') break;
  62.     istrstream input(buf, 10);
  63.     input >> recnum;
  64.   }
  65. } ///:~
  66.