Thread: Writing to a File, then clearing it.

  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-21-2008, 11:19 PM
  4. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  5. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM