Thread: Very Simple Data file question...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    27

    Very Simple Data file question...

    I already have a list of stuff in my data.txt file.

    How do I add stuff to that data.txt file without erasing what's already in it?

    Thanks in advance

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    You open the file with the ios::app mode.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    ofstream outfile("data.txt", ofstream::ate);

    opens the file in append mode.

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    27
    Here is what I have tried...

    string newdata;

    ofstream fout ("data.txt", ios:app);

    fout << newdata;


    When I do this though, it erases everything that was already in it.

    I also tried the same only with ofstream::ate and it did the same thing. It erases everything and writes only newdata;
    Last edited by noodle24; 09-23-2006 at 12:35 PM.

  5. #5
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    ios::app

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    27
    Yes that was just a typo. I have tried ios::app

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    could you post your code? There may be something else causing this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 04-15-2009, 10:35 AM
  2. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  3. simple file I/O question
    By loopshot in forum C Programming
    Replies: 2
    Last Post: 11-30-2006, 02:59 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM