00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "OStack.h"
00018 #include "require.h"
00019 #include <fstream>
00020 #include <iostream>
00021 #include <string>
00022 using namespace std;
00023
00024
00025
00026 class MyString: public string, public Object {
00027 public:
00028 ~MyString() {
00029 cout << "deleting string: " << *this << endl;
00030 }
00031 MyString(string s) : string(s) {}
00032 };
00033
00034 int main(int argc, char* argv[]) {
00035 requireArgs(argc, 1);
00036 ifstream in(argv[1]);
00037 assure(in, argv[1]);
00038 Stack<Object> textlines;
00039 string line;
00040
00041 while(getline(in, line))
00042 textlines.push(new MyString(line));
00043
00044 MyString* s;
00045 for(int i = 0; i < 10; i++) {
00046 if((s=(MyString*)textlines.pop())==0) break;
00047 cout << *s << endl;
00048 delete s;
00049 }
00050 cout << "Letting the destructor do the rest:"
00051 << endl;
00052 system("pause");
00053 }