Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!umriscc!mcs213f.cs.umr.edu!jamesh From: jamesh@cs.umr.edu (James Hartley) Newsgroups: comp.os.msdos.programmer Subject: Are streams w/n classes flaky? Message-ID: <1752@umriscc.isc.umr.edu> Date: 27 Nov 90 21:23:28 GMT Sender: news@umriscc.isc.umr.edu Organization: University of Missouri - Rolla Lines: 49 Originator: jamesh@mcs213f.cs.umr.edu I recently tried to simulate persistent objects in C++ with the code given below using Turbo C++. The results that I got were quite erratic. Has anyone else has problems with declaring and using streams within classes? ---------------------------- BEGIN CODE ------------------------------------ #include #include #include class persist { char *fname; protected: fstream dskfile; public: persist(char *fn) { fname = new char[strlen(fn) + 1]; strcpy(fname, fn); dskfile.open(fname, ios::in | ios::out); if (!dskfile) { cerr << "error in opening file\n"; exit(1); } } ~persist(void) { dskfile.close(); delete fname; } }; class constant : public persist { unsigned int k; public: constant(char *fn) : persist(fn) { dskfile >> k; } unsigned int get_constant(void) { return k; } }; main() { constant k("CONSTANT.TXT"); cout << "k = " << k.get_constant << "\n"; return 0; } ---------------------------- END CODE ------------------------------------ -- James J. Hartley Internet: jamesh@cs.umr.edu Department of Computer Science Bitnet: jamesh@cs.umr.edu@umrvmb.bitnet University of Missouri - Rolla UUCP: ...!uunet!cs.umr.edu!jamesh