Error using ofstream close()

Discussion in 'C++' started by Colum, Dec 19, 2003.

  1. Colum

    Colum Guest

    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);
    }
    Colum, Dec 19, 2003
    #1
    1. Advertising

  2. Colum

    Moonlit Guest

    Hi,

    "Colum" <> wrote in message
    news:pQAEb.1480$...
    > 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.
    Moonlit, Dec 19, 2003
    #2
    1. Advertising

  3. Colum wrote in news:pQAEb.1480$:

    > 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.
    --
    http://www.victim-prime.dsl.pipex.com/
    Rob Williscroft, Dec 19, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Squid Seven

    ofstream * vs. ofstream

    Squid Seven, Jul 13, 2005, in forum: C++
    Replies:
    5
    Views:
    597
    Ivan Johansen
    Jul 14, 2005
  2. Fraser Ross

    ofstream and close()

    Fraser Ross, Mar 29, 2006, in forum: C++
    Replies:
    4
    Views:
    384
    Fraser Ross
    Mar 31, 2006
  3. Replies:
    15
    Views:
    712
    Old Wolf
    Mar 4, 2007
  4. aaragon
    Replies:
    15
    Views:
    609
    James Kanze
    Sep 28, 2007
  5. Iñaki Baz Castillo
    Replies:
    7
    Views:
    845
    Iñaki Baz Castillo
    Jan 12, 2010
Loading...

Share This Page