Thread: fstream

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

    Red face fstream

    I am learning I/O, using fstream to read and write to files. If I have a file that already has data in it, and I want to change some of that data, what mode do I use?? eg. to append I use ios::app
    Like if I have a file containing an employee's name and age, and I wanted to open the file and change the age, how do I do that??
    Also, one webpage said ios::ate allows you to append ANYWHERE in the file, but it only allows me to append the end of the file. What am I doing wrong??

  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 "insert" mode for any kind of file operation. You can replace a fixed-length record in a file with another fixed-length record or you can append whatever you want to the end of a file.

    If it's more complex than that, you basically have to create a new file with a mix of the old file you want to keep, and the changes you want to apply.
    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
    Aug 2006
    Posts
    4
    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with fstream, one variabile for write and read
    By Smjert in forum C++ Programming
    Replies: 3
    Last Post: 02-03-2009, 10:19 PM
  2. Fstream. I/O
    By kevinawad in forum C++ Programming
    Replies: 2
    Last Post: 07-07-2008, 09:19 AM
  3. ARGH! fstream errors
    By OttoDestruct in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2004, 10:37 PM
  4. Are fstream and ofstream incompatible?
    By johnnyd in forum C++ Programming
    Replies: 5
    Last Post: 03-19-2003, 12:21 PM
  5. Problems with fstreams.
    By mosdef in forum C++ Programming
    Replies: 7
    Last Post: 06-19-2002, 03:36 PM