Writing to a File, then clearing it.

This is a discussion on Writing to a File, then clearing it. within the C++ Programming forums, part of the General Programming Boards category; Hi, I need to know how to erase the contents a text file after I have written to it, using ...

  1. #1
    Registered User BigSter's Avatar
    Join Date
    Nov 2001
    Posts
    47

    Cool Writing to a File, then clearing it.

    Hi, I need to know how to erase the contents a text file after I have written to it, using ofstream.
    Thanks

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    The default behavior on opening a file with ios:ut is to create it if it doesn't exist, and delete the contents if it does. So you could close the file then reopen it.
    You can also use ios::trunc to delete the contents.

  3. #3
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    The smiley should be ios::out
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  4. #4
    Registered User BigSter's Avatar
    Join Date
    Nov 2001
    Posts
    47
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-22-2008, 12:19 AM
  4. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 01:36 PM
  5. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 11:51 PM

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