Thread: Adding to a file

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    4

    Arrow Adding to a file

    I have a tab delimited text file which is filled with data from an rc file. I want to add another column to each line of the file after the first two '\n's.
    This is the code I have at the moment:

    Code:
    fstream Glossary;
    Glossary.open("file.txt");
    Glossary.seekg(pos);
    while(!Glossary.getline(val, 100).eof()) {
    Glossary.ignore(100, '\t');
    Glossary.ignore(100, '\t');
    Glossary<<Offset+1<<'\t';
    }
    Glossary.close();
    This code isn't actually adding anything to the file though. When i debug it it seems to find the right place to add the new text but it doesn't actually do it... Any ideas? If there's another, better way to do this please let me know. Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    There is no file insert functionality.

    You read in the old file, and write out the new file with whatever changes you need to apply, on a line by line basis.

    Then you delete the old file and rename the new file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    4
    Ah ok. Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM