|
|
|
|
|
|
| Author |
Message |
Richard Herring *nix forums Guru
Joined: 21 Feb 2005
Posts: 336
|
Posted: Fri Jul 21, 2006 11:10 am Post subject:
Re: how can i use fstream object to clear file's content?
|
|
|
In message <e9q3hq$6kr$1@news.Stanford.EDU>, Alan Johnson
<alanwj@no.spam.stanford.edu> writes
| Quote: | horneye wrote:
After i use fstream to open a file, how can i use the fstream object
to clear file's content?
std::ofstream("filename") ;
Just opening it as such should be sufficient to cause the data to be
truncated.
True, there will now be an empty file called "filename", but it depends |
on the underlying operating system whether that is the same thing as
"clearing" an existing file's contents. On some OS's the previous
version of the file may still exist. Whether that distinction is
important depends on the OP's application.
Except for this special case of "truncate to zero length" (which may
actually be implemented as "replace with a new empty file") , the C++
file model doesn't allow you to reduce the size of an existing file,
only to overwrite or extend it.
--
Richard Herring |
|
| Back to top |
|
 |
Alan Johnson *nix forums Guru Wannabe
Joined: 14 May 2005
Posts: 206
|
Posted: Fri Jul 21, 2006 8:34 am Post subject:
Re: how can i use fstream object to clear file's content?
|
|
|
horneye wrote:
| Quote: | After i use fstream to open a file, how can i use the fstream object
to clear file's content?
|
std::ofstream("filename") ;
Just opening it as such should be sufficient to cause the data to be
truncated.
--
Alan Johnson |
|
| Back to top |
|
 |
horneye *nix forums beginner
Joined: 24 May 2006
Posts: 2
|
Posted: Fri Jul 21, 2006 7:52 am Post subject:
how can i use fstream object to clear file's content?
|
|
|
After i use fstream to open a file, how can i use the fstream object
to clear file's content? |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Wed Dec 03, 2008 11:12 pm | All times are GMT
|
|
Books | Shares | Best Credit Cards | Currency Converter | Mortgage Loans
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|