473,395 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

~destructor trouble

TMS
119 100+
I'm a little rusty with C++ so bear with me.

My assignment has me amending a database file by adding 'tombstones' to records that are to be omitted later by the destructor. The database brings in a file (lets call it A) then there is a menu of operations. If the user wants to remove a file, they use the remove option which places a 'b' (in this case) in front of the Social Security Number.

That is all fine and good. My amendments take care of that. NOW, I'm having problems writing the new database that excludes the tombstoned records. I can get it to print to the screen, but I can't get it to print out. I know I need to define an fstream object, and use it in a function called writeToFile(). But it doesn't work.

database is declared as a type fstream

Here is my destructor:

//function to omit tombstoned items, write data to file
template<class T>
Database<T>::~Database()
{
T tmp; //variable to access student file
fstream newDatabase; //my attempt at declaring the new database object

database.open(fName,ios::in|ios::binary); //this works fine
while (true )
{
tmp.readFromFile(database);
if database.eof()) //finish when at the end of file
break;
if(!tmp.isNull()) //check for tombstone
{
//newDatabase = database; //doesn't work
//tmp.writeToFile(newDatabase); //this causes
//infinite loop
cout << tmp << endl; // omits tombstoned items //prints to screen just fine
}
}

database.close();
}

any suggestions?
Sep 12 '06 #1
1 1926
have you received any replies? It seems that there are some pieces missing within your destructor. Post the whole code and i'll check it out.
Dec 25 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Timothy Madden | last post by:
Hy I have destructors that do some functional work in the program flow. The problem is destructors should only be used for clean-up, because exceptions might rise at any time, and destructors...
37
by: WittyGuy | last post by:
Hi, I wonder the necessity of constructor and destructor in a Abstract Class? Is it really needed? ? Wg http://www.gotw.ca/resources/clcm.htm for info about ]
4
by: iTooo | last post by:
What a subject, mhhh not resumable. Here is my problem: I'm using a template class for lists, upon deletion it deletes its elements, ok, works fine. Trouble comes when I put in this list...
11
by: Ken Durden | last post by:
I am in search of a comprehensive methodology of using these two object cleanup approaches to get rid of a number of bugs, unpleasantries, and cleanup-ordering issues we currently have in our...
8
by: JAL | last post by:
According to MSDN2, if a managed class throws an exception in the constructor, the destructor will be called. If an exception is thrown in the constructor the object never existed so how in the...
10
by: piboye | last post by:
Hi ! I'm a academician in china. I have been intereted in C++ lasting. In reading the C++ Primer book, i have a trouble about union. In the book ,it said that union can have constructors and...
3
by: Noah Roberts | last post by:
I am trying to pull behavior out of a class so that the class can be replaced. Part of that behavior takes place in the destructor of the object. I need call sites to change so that they call a...
3
schmals
by: schmals | last post by:
I am building a bigint class and currently having an issue with overloading operators simple +, -, and * operators with my destructor. The bigint class contains a dynamically allocated array of...
3
by: GAURAV AGRAWAL | last post by:
Hi Guys, Can someone please explain me why this is happening #include<iostream> using namespace std; class a { public: int a1; // If I remove this it'll work fine
9
by: itdevries | last post by:
Hi, I've ran into some trouble with an overloaded + operator, maybe someone can give me some hints what to look out for. I've got my own custom vector class, as a part of that I've overloaded...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.