editing data in a data file

This is a discussion on editing data in a data file within the C++ Programming forums, part of the General Programming Boards category; hi..is it possible clear data in a .dat file. lets say my file initially has: ******* my name is sujeet. ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    24

    editing data in a data file

    hi..is it possible clear data in a .dat file.

    lets say my file initially has:

    *******
    my name is sujeet.
    *******

    Now i want to clear all that data and have my file data:

    *******
    sujeet is my name.
    *******

    is it possible?wat function to use?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    The same functions you used to write the file in the first place.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    24
    but how do i erase the data in the data file?

    waht command?

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    ofstream out ("somefile", std::ios::trunc);
    or to add to it but not delete
    ofstream out ("somefile", std::ios::app);

    just search google for a fstream reference.

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    By data file you mean a .txt file? You need to #include <fstream> so you can read/write from files, atleast on a console program. There is no "erasing" of other data, you just write over it.

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    scwizzo: I dont know if I misunderstood you, but <fstream> will read any file. Also, you can "erase" data from a file. Maybe not bits and pieces, but you can delete the whole thing, but then again if you can write it once, you can surely write the data to the file again.

    If I were the OP I would get on cppreference.com and learn about file I/O. I had my problems with it, as everyone else did once or twice. I think a good reference would be a great place to start.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 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
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  3. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  4. Editing a data file
    By Strait in forum C++ Programming
    Replies: 7
    Last Post: 02-05-2005, 03:21 PM
  5. File Database & Data Structure :: C++
    By kuphryn in forum C++ Programming
    Replies: 0
    Last Post: 02-24-2002, 10:47 AM

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