Thread: Adding items to the beginning of a file

  1. #1
    Autobots Transform! Dunners's Avatar
    Join Date
    Feb 2005
    Posts
    23

    Adding items to the beginning of a file

    Hi,

    Is it possible to add items to the beginning of an existing file without overwriting the data that already exists in the file? I have tried using ios::app but that only seems to let me append the end of the file.

    Cheers
    "Yes, I rather like this God fellow. He's very theatrical, you know, a pestilence here, a plague there. Omnipotence. Gotta get me some of that."
    - Stewie Griffin

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You have to do it manually. Probably the easiest way is to:
    1. Create a new file.
    2. Add the new content to your new file.
    3. Append the contents of the old file to the new file.
    4. Rename the new file to the old file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM