File Existance

This is a discussion on File Existance within the C++ Programming forums, part of the General Programming Boards category; 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 ...

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

    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,789
    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,399
    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, 04:02 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  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