Thread: Getting an input stream to stop creating a file

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    8

    Question Getting an input stream to stop creating a file

    Hi,

    Code:
    #include <fstream.h>
    
    ifstream DATABASE_IN;
    DATABASE_IN.open("afw.raw", ios::in || ios::binary || ios::nocreate);
    This should open an instream from the binary file "afw.raw", if it exists.... but it shouldn't create the file if it doesn't already exist. Lo and behold, everytime I run the program, it has created the file "afw.raw". What am I doing wrong? How can I make sure that the file isn't created?

    Thanks

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    You're using a logical OR instead of a bitwise OR. Use just 1: | between the 2nd parameters different values.
    Last edited by jdinger; 03-21-2003 at 03:47 PM.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    8
    That worked. Thanks.

  4. #4
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    No problem. Also, you are using the depricated form of the fstream header. I'd recommend using the newer standard version. With it you don't have to declare ios::nocreate ('nocreate' actually doesn't exist anymore) because if it doesn't exist with ifstreams it won't create it by default.

    Code:
    #include <fstream> //notice no ".h"
    
    int main(void)
    {
       ifstream DATABASE_IN;
       DATABASE_IN.open("afw.raw",ios::binary); //this is all you need
       //all your other stuff here.....
       return(0);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  5. Input file stream problems
    By Shadow12345 in forum C++ Programming
    Replies: 10
    Last Post: 10-06-2002, 06:33 PM