Error using ofstream close()

C

Colum

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::eek:ut);
while(!outFile.is_open())
{
cout<<"Please insert disk into A: drive and press key"<<endl;
getch();
outFile.open(out,ios::eek:ut);
}
 
M

Moonlit

Hi,

Colum said:
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::eek:ut);
while(!outFile.is_open())
{
cout<<"Please insert disk into A: drive and press key"<<endl;
getch();
outFile.open(out,ios::eek:ut);
}

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.
 
R

Rob Williscroft

Colum wrote in
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::eek:ut);
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::eek:ut);
}

HTH.

Rob.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top