[Solved] Why is it not possible to erase contents from a file in C++? [closed]


Does any other language support this?

C++ supports it. You can seek and you can write. But the fact that this is a very uncommon scenario to replace the same exact byte length and the fact that replacing a bunch of bytes with another bunch of bytes that has a different length is horribly inefficient to a point were writing a new file is faster, lead to the language and functions that exist.

Other languages may handle this differently, but I have yet to learn one that actually does. Because file handling does not change across languages and all language and framework writers came to the same conclusions: files are not the best medium for insertion and deletion of data. Arrays are not the best medium for insertion and deletion, files just being one them.

If you need to insert and delete, use another container (lists come to mind). If you need to persist this container to disk, do so after all manipulation is done.

3

solved Why is it not possible to erase contents from a file in C++? [closed]