Monday, 10 December 2012
Test Two Q4:
The answer for the question 4 for test two:
templat <class T>class SQueue : public Queue<T>, public fstream {
char* _fname;
public: SQueue(const char* fname):Queue(),fstream(fname, ios::binary|ios::in|ios::out) {
_fname = new char[strlen(fname) + 1];
strcpy(_fname, fname);
open(fname, ios::binary|ios::in);
seekg((ios::pos_type)0 ,ios::beg);
T t;
while (read((char*)&t,sizeof(T))) {
Queue::Add(t);
}
close();
}
~SQueue() {
T t;
open(_fname, ios::out|ios::binary );
seekp((ios::pos_type)0 ,ios::beg);while (t=Remove()) {
write((char*)t,sizeof(T));
}
close();
}
};
intmain() {
SQueue<int> sq("c:\atieh\test.bin");
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment