Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Error using ofstream close()

Reply
Thread Tools

Error using ofstream close()

 
 
Colum
Guest
Posts: n/a
 
      12-19-2003
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:ut);
while(!outFile.is_open())
{
cout<<"Please insert disk into A: drive and press key"<<endl;
getch();
outFile.open(out,ios:ut);
}


 
Reply With Quote
 
 
 
 
Moonlit
Guest
Posts: n/a
 
      12-19-2003
Hi,

"Colum" <(E-Mail Removed)> wrote in message
newsQAEb.1480$(E-Mail Removed)...
> 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:ut);
> while(!outFile.is_open())
> {
> cout<<"Please insert disk into A: drive and press key"<<endl;
> getch();
> outFile.open(out,ios: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.


 
Reply With Quote
 
 
 
 
Rob Williscroft
Guest
Posts: n/a
 
      12-19-2003
Colum wrote in newsQAEb.1480$(E-Mail Removed):

> 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: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:ut);
> }
>


HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compilation error using ofstream aaragon C++ 15 09-28-2007 11:44 AM
Confused with error using ofstream rEvolution27@gmail.com C++ 15 03-04-2007 10:21 PM
ofstream * vs. ofstream Squid Seven C++ 5 07-14-2005 07:34 AM
ofstream error conditions jois.de.vivre@gmail.com C++ 3 06-03-2005 12:42 AM
ofstream file error checks? steve C++ 2 08-20-2003 12:28 AM



Advertisments