Truncating a fstream opened in ios::ate mode 
Author Message
 Truncating a fstream opened in ios::ate mode

If I open a datafile in ios::ate (opens for writing but does not clear it)
mode, is there a way to truncate the file after a certain byte offset? In
some instances, I need to write to the middle of the file and cut off the
rest. Please, no MS specific answer (I would try comp.lang.*, but seeing
that my newsgroup server is down, this is my only resort)

Thanks for any help

Dan Watt



Sat, 10 May 2003 03:00:00 GMT  
 Truncating a fstream opened in ios::ate mode

Quote:

> If I open a datafile in ios::ate (opens for writing but does not clear it)
> mode, is there a way to truncate the file after a certain byte offset? In
> some instances, I need to write to the middle of the file and cut off the
> rest. Please, no MS specific answer (I would try comp.lang.*, but seeing
> that my newsgroup server is down, this is my only resort)

There is no standard way to truncate a file in-place.  The standard
alternative to truncation would be to copy the required data to a
temporary file (or into memory) and then to overwrite the original
file with that data.

--
Any opinions expressed are my own and not necessarily those of Roundpoint.



Fri, 16 May 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. how to truncate a file opened in text mode

2. ios::showpoint and ios::fixed

3. ios::nocreate, ios::noreplace, filebuf::openprot

4. CHtmlView - opened ppt presentation eats all shortcuts

5. fstream::open

6. error opening fstream on second file

7. Trying to open file with fstream

8. fstream cannot handle 46+ concurrently open files

9. CFile/Fstream not opening

10. Truncating an open file on UNIX

11. TRUNCATING OPENED TEXT FILE

12. Truncating a binary file opened for read and write

 

 
Powered by phpBB® Forum Software