The "\0" is just the C++ way of representing a character code of zero, which is not the same as the digit zero "0".
If you view the file using a hex editor for example, you will see 00 (hex) which is a single character, in the same way that the digit '0' would appear as 30 (hex).
I see the requirements:
Each line has to be able to vary in length, and the number of lines must be able to vary. |
An update to an ordinary sequential file with those requirements suggests one of two approaches:
1. Allow extra blank space to accommodate possible changes.
advantage - simple and fast to implement
disadvantage - file may be
much larger than necessary.
may not be flexible enough.
2. Apply the updates by rewriting the entire file.
advantage - file size is kept as small as possible
d
isadvantage - performance may be slow. Real-world systems often store up a batch of changes in a transaction file, and apply them all at once, avoiding excessive file i/o.
There are other options:
3. See for example, "Random Access with Variable Length Records" here:
http://cplus.about.com/od/learning1/ss/random_7.htm
Personally I'd avoid this as the programming overhead could be significant.
Another possibility exists:
4. Use a file organisation which allows random access - such as a database.
advantage - completely flexible as to both the variation in size and the ability to update any part without affecting the rest.
Fast.
disadvantage - requires some sort of database to be set up.
also requires some knowledge how to access the database, e.g. using SQL