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.
- simple and fast to implement
- file may be much
larger than necessary.
may not be flexible enough.
2. Apply the updates by rewriting the entire file.
- file size is kept as small as possible
- 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:
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.
- completely flexible as to both the variation in size and the ability to update any part without affecting the rest.
- requires some sort of database to be set up.
also requires some knowledge how to access the database, e.g. using SQL