file handling

This is a discussion on file handling within the C++ Programming forums, part of the General Programming Boards category; how can i check the file which i intend to open exist or not?I must terminate the program if user ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    113

    file handling

    how can i check the file which i intend to open exist or not?I must terminate the program if user enters non existing file.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    attempt to open it. If open failes then do the error handling routine.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    113
    that's what i want to ask. Which function will i have to use.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    this is c++ board, just open the file the normal way
    Code:
    ifstream in(filename);
    if( !in.is_open())
    {
        cout << "oops!  can't open file" << filename << endl;
        return 1;
    }

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    113
    thanks for help

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    113
    Error:is_open() is not a member of ifstream

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    what header files did you use? (without the .h extension ??????)
    Code:
    #include <fstream>
    
    using namespace std;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating File Handling Functions
    By td4nos in forum C Programming
    Replies: 6
    Last Post: 06-26-2009, 12:43 PM
  2. basic file handling problem
    By georgen1 in forum C Programming
    Replies: 4
    Last Post: 03-05-2009, 06:21 AM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 04:44 PM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 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

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