Writing to a file without overwriting what was writen before?

This is a discussion on Writing to a file without overwriting what was writen before? within the C++ Programming forums, part of the General Programming Boards category; I am making a program with a simple link list class, each node holds an arry and a int. I ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    118

    Question Writing to a file without overwriting what was writen before?

    I am making a program with a simple link list class, each node holds an arry and a int. I made a Method where you create a new node and give it information, then it writes the information to a file. The problem is that when it writes the info to the file, it overwrites what was written before, thus the file only contains the information of the last node. Any help?
    Why drink and drive when you can smoke and fly?

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,798
    Open your file in append mode.
    Code:
    ofstream file;
    file.open("whatever.txt",ios::out|ios::app);
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    118

    Thanks a lot.

    Why drink and drive when you can smoke and fly?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble writing to file using fwrite()
    By yougene in forum C Programming
    Replies: 4
    Last Post: 12-30-2008, 04:13 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  3. Writing to a file without overwriting
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2002, 09:21 PM

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