Thread: File Existance

  1. #1
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401

    Question File Existance

    Code:
    ofstream a_file("test.txt", ios::nocreate);
    If I run the above line of code and test.txt does not exists, is there some sort of return code that I can check to verify that it does not exist?

    Ex.
    Code:
    ofstream a_file("test.txt", ios::nocreate);
    if (SOME_CONDITION)
    {
       //file does not exist, do something
    }
    //file does exist, do something else
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Code:
    ofstream a_file("test.txt", ios::nocreate);
    if (! a_file.is_open()){
       //file does not exist, do something
    }
    //file does exist, do something else

  3. #3
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Thanks
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  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