ofstream woes

OK. I am calling a function and passing data to it and I want to write to a file using ofstream. Now, it works except for the fact that the file keeps having records overwritten (probably because it's being opened and closed everytime the function is called).

Here's what the function looks like:

void *writeFile(void *argument, bool bPrime, long testNo, long *factor, int factorLimit)
{ int i;
ofstream outFile;
outFile.open((char *) argument, ios::out);

//Looks to see if the file is false.
if (!outFile)
cout<<"outFile is false\n";
if (outFile.good())
{ outFile.clear();
outFile.seekp(ios_base::end);
outFile <<"Number tested: " <<testNo <<endl;
if (bPrime == 1)
outFile <<"The number is prime."<<endl;
if (bPrime == 0)
{ outFile <<"The number isn't prime." <<endl
<<"Factors: ";
for (i=0; i<factorLimit; i++)
{ outFile <<factor[i];
if (i != factorLimit-1)
outFile<<", ";
}
}
outFile.close();
}
return NULL;
}

Why do all the records keep disappearing? Thanks.
[1357 byte] By [Sivakk] at [2007-11-20 11:15:26]
# 1 Re: ofstream woes
I have not tried it, but this should work.

for this line

outFile.open((char *) argument, ios::out);

you should add something to the second parameter, like this:

outFile.open((char *) argument, ios::out | ios::app);

this appends any new data to the end of the file
nerdykid at 2007-11-9 1:25:16 >
# 2 Re: ofstream woes
You are my hero, thanks!
Sivakk at 2007-11-9 1:26:18 >
# 3 Re: ofstream woes
Your Welcome.

And in case you were wondering where I got it from, here is a link to the page.
http://www.cplusplus.com/doc/tutorial/files.html

It has lots of helpful tips about using the ofstream class.
nerdykid at 2007-11-9 1:27:17 >