Thread: writing back to the file

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    32

    writing back to the file

    I am trying to write back to the beginning of a file using the following:

    Code:
     outfile.open(fileName, ios::in|ios::nocreate)
    Yes it writes to the beginning of the file but it seems to overwrite some of the information already there. How can I prevent this from occuring.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    You can't just insert new data at the beginning of a file. Naturally anything you write will overwrite what's already there. If you want to insert something at the beginning of a file then you'll need to either use a dynamic data structure in memory to work with the file, or write what you want to a temporary file, then append the contents of the file to the temporary, then copy the temporary back to the original file.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    32
    Ohhh

    Thanx for that. Had no idea that was the case

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM