-1

This is my first post here. I am writing a program in C++ using file handling in which I have a given text file and I wish to delete everything in the file beyond a certain point at which my pointer is, after which the pointer should return to the same plae as before.

If anyone can help me I will be greatly obliged. I have not programmed in a long time.

Specifically in my program, I have,

...

ofstream List;

List.open("List.txt");

...

List.seekp(i);

At this point I wish to delete everything in the file beyond the ith byte, and ensure that whatever further I write is from the ith place. How do I do that?

Thanks.

Shahab
  • 101
  • 3

1 Answers1

1

Typically in text file processing you use two files, read from original and write to temp. Then close temp, unlink original and rename temp to original. One reason for doing it this way is that you don't lose everything if there is a crash part way through. Second reason is that trying to do anything tricky may not work when you try to use it on a different filesystem.

stark
  • 12,615
  • 3
  • 33
  • 50