Opening and closing files

This is a discussion on Opening and closing files within the C++ Programming forums, part of the General Programming Boards category; Could something like this be done in a the same program. Im trying to figure out why I cannot open ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    32

    Opening and closing files

    Could something like this be done in a the same program. Im trying to figure out why I cannot open a file I just wrote to. If it cannot be done then problem found. Or is this a big NO NO?
    Code:
    inData.open("qwert.dat");
    outData.open("asdfg.dat");
    
    /////////////////
    Do some stuff
    /////////////////
    
    inData.close();
    outData.close();
    
    inData.open("asdfg.dat");        //open the file I just wrote and closed
    
    /////////////////
    Do some stuff
    /////////////////
    
    inData.close();                         //close the file again
    
    /////////////////
    Do some stuff
    /////////////////
    
    outData.open("asdfg.dat");     //doing this blanks the file
    
    /////////////////
    Do some stuff
    /////////////////
    
    outData.close();

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    6
    when you open a file to write to it will put the "cursor" at the beginig of the file.
    so if you want to add to the end of the file you need to append the file, so that it will add to the bottom of the file rather then the top
    alas, i only have partial commands for that.
    hope someone else can provide the syntax for ya

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Last edited by Monster; 11-26-2002 at 04:02 AM.

  4. #4
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    use ios::app it will do the job.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading log files as they're being appended
    By guesst in forum Windows Programming
    Replies: 4
    Last Post: 06-05-2008, 11:52 AM
  2. Replies: 5
    Last Post: 02-11-2008, 01:36 AM
  3. Replies: 11
    Last Post: 01-10-2007, 06:53 AM
  4. Which style of if loops is most common?
    By dwks in forum A Brief History of Cprogramming.com
    Replies: 38
    Last Post: 08-25-2005, 04:18 PM
  5. Programs opening programs
    By LinuxPLC in forum C Programming
    Replies: 1
    Last Post: 11-21-2002, 12:50 PM

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