Thread: Reprompt File Request

  1. #1
    Registered User
    Join Date
    Sep 2006

    Question Reprompt File Request

    My code reads something like
    ifstream fin;
    cout << "enter filename:";
    cin >> filename;
    a = OpentheFile(filename, fin);
    the return type of OpentheFile is a bool. If I return a '1' (TRUE) then the file is opened & stuff is done. However, if I return a '0' (FALSE) - meaning the file was nonexistant, how can I reprompt the user to enter another filename until an existant filename is entered?

    My loops are messed up..

    any help greatly appreciated.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    do {
      - prompt a filename
    } while ( ! ( a = OpentheFile(filename, fin) ) );
    Of course if a is just there to test
    while ( ! OpentheFile(filename, fin) );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2006
    i just figured it out! thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. archive format
    By Nor in forum A Brief History of
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM