truncate/decrease file

N

Neo

I want to remove 10 bytes from end of the file, how I can perform this
task using C++ filing functions?
I am not want to make new, write contents, remove input file and rename
output file.
In C++ ios::trunc flag available use for truncation but how to use
trunk flag in my task?

Regard,
-aims
 
K

Kristo

Neo said:
I want to remove 10 bytes from end of the file, how I can perform this
task using C++ filing functions?
I am not want to make new, write contents, remove input file and rename
output file.
In C++ ios::trunc flag available use for truncation but how to use
trunk flag in my task?

ios::trunc, along with ios::eek:ut, is the default open mode for a file
opened by an ofstream object. That means when you open a file for
writing, it is truncated to zero, i.e., cleared. So if you want to
truncate 10 bytes off a file...

1. open the file for reading
2. read the contents into a buffer
3. close the file
4. open it for writing
5. write out the buffer except the last 10 bytes.

Kristo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top