Thread: Loading file

  1. #1
    Registered User
    Join Date
    Apr 2002

    Loading file


    I was wondering why my code works in some cases and not in others. This code is part of a function call that loads information into a vector, then it goes back to a menu. I'm trying to check to see if the filename entered is valid. If I enter a valid filename the first time around, everything works fine. But if I enter an invalid filename, I'm brought back to the menu, and then when I go into the load function again, even if I enter a valid file name it tells me that it is not valid. I don't understand why...

    Any suggestions or comments would be appreciated.

    cout << "\n\nPlease enter the name of the file: ";
    cin >> filename;;

    if (!infile)
    cout << "\n\nThat is not a valid file. Please try again.\n\n";
    } // End if

    else if (infile.good())
    while (!infile.eof())
    Puts files in vector
    } // End while


    } // End if

    Menu( );

  2. #2
    Registered User
    Join Date
    Apr 2002
    Well, I found it!! My ifstream infile wasn't in the right spot....

    Thanks for taking the time to look at my post though!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. archive format
    By Nor in forum A Brief History of
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM