Adding items to the beginning of a file

This is a discussion on Adding items to the beginning of a file within the C++ Programming forums, part of the General Programming Boards category; Hi, Is it possible to add items to the beginning of an existing file without overwriting the data that already ...

  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, 05: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, 08:54 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09: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, 05:10 PM

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