help: ofstream doesn't always create files?

J

james545

I am having a problem with ofstream creating files. Sometimes when I
run the program, ofstream creates a new file for writing and writes to
it. No problem. But sometimes it fails to create the files
altogether. Why doesn't it create files consistently?
(My disk isn't full, and the file didn't previously exist)
Thanks for your help.

sample code:
------------------
ofstream outfile;
outfile.open(fileName, ios::eek:ut | ios::trunc);
if (outfile){
outfile << "my text" << endl;
}
else{
printf("failed to open\n");//for some reason it fails to create a
file sometimes.
}
outfile.close();
------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top