Reprompt File Request

This is a discussion on Reprompt File Request within the C++ Programming forums, part of the General Programming Boards category; My code reads something like Code: ifstream fin; cout << "enter filename:"; cin >> filename; a = OpentheFile(filename, fin); the ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    10

    Question Reprompt File Request

    My code reads something like
    Code:
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,490
    Code:
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    10
    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, 04: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 Cprogramming.com
    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, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21