By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,588 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

Error using ofstream close()

P: n/a
Hi,
I am trying to write data out to a file on floppy disk,
If the disk is present in the drive the program runs fine and outputs the
data correctly, however if the disk is not present in the drive, the program
enters the while loop which asks user to insert the disk and continuously
tries to open it, after the user has inserted the disk the program seems to
run fine, however there is no data in the output file.I think it could be a
problem with close() (not having a handle to the file) not opperating
properly, some code used:-

outFile.open(out,ios::out);
while(!outFile.is_open())
{
cout<<"Please insert disk into A: drive and press key"<<endl;
getch();
outFile.open(out,ios::out);
}
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

"Colum" <co********@hotmail.com> wrote in message
news:PQ****************@news.indigo.ie...
Hi,
I am trying to write data out to a file on floppy disk,
If the disk is present in the drive the program runs fine and outputs the
data correctly, however if the disk is not present in the drive, the program enters the while loop which asks user to insert the disk and continuously
tries to open it, after the user has inserted the disk the program seems to run fine, however there is no data in the output file.I think it could be a problem with close() (not having a handle to the file) not opperating
properly, some code used:-

outFile.open(out,ios::out);
while(!outFile.is_open())
{
cout<<"Please insert disk into A: drive and press key"<<endl;
getch();
outFile.open(out,ios::out);
}


Well, if this is the program there shouldn't be any data in the outFile,
where is the part that is writing data in it?

Regards, Ron AF Greve.
Jul 22 '05 #2

P: n/a
Colum wrote in news:PQ****************@news.indigo.ie:
Hi,
I am trying to write data out to a file on floppy disk,
If the disk is present in the drive the program runs fine and outputs
the
data correctly, however if the disk is not present in the drive, the
program enters the while loop which asks user to insert the disk and
continuously tries to open it, after the user has inserted the disk
the program seems to run fine, however there is no data in the output
file.I think it could be a problem with close() (not having a handle
to the file) not opperating properly, some code used:-

outFile.open(out,ios::out);
while(!outFile.is_open())
{
cout<<"Please insert disk into A: drive and press key"<<endl;
getch();
You need to clear the error state before you can succesfully retry
the open.

outFile.clear();
outFile.open(out,ios::out);
}


HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.