home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C07 / Stash3Test.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  978 b   |  36 lines

  1. //: C07:Stash3Test.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} Stash3
  7. // Function overloading
  8. #include "Stash3.h"
  9. #include "../require.h"
  10. #include <fstream>
  11. #include <iostream>
  12. #include <string>
  13. using namespace std;
  14.  
  15. int main() {
  16.   Stash intStash(sizeof(int));
  17.   for(int i = 0; i < 100; i++)
  18.     intStash.add(&i);
  19.   for(int j = 0; j < intStash.count(); j++)
  20.     cout << "intStash.fetch(" << j << ") = "
  21.          << *(int*)intStash.fetch(j)
  22.          << endl;
  23.   const int bufsize = 80;
  24.   Stash stringStash(sizeof(char) * bufsize, 100);
  25.   ifstream in("Stash3Test.cpp");
  26.   assure(in, "Stash3Test.cpp");
  27.   string line;
  28.   while(getline(in, line))
  29.     stringStash.add((char*)line.c_str());
  30.   int k = 0;
  31.   char* cp;
  32.   while((cp = (char*)stringStash.fetch(k++))!=0)
  33.     cout << "stringStash.fetch(" << k << ") = "
  34.          << cp << endl;
  35. } ///:~
  36.