I want to remove some information from a text file without shifting its all records. For example a text file customers.txt is given. it have a lot of records seperated by # delimiter. and each record contains fields separated by ;. Like this: 1665;John;Smith given a customer id, I want to remove a customer with corresponding id. I can find offset and length of the record in the file, but don’t know how to remove it. do i have to re-write whole file?
Note: I’m using Standard C++ with g++4.5 and libst4.
You have a couple of choices.
1) rewrite the remainder of the file past the record you are removing.
2) replace the record with some indicator that it is removed and handle that in your parsing of the file (like replacing the entry being removed with # or some other special character).