mlewis54
mlewis54

Reputation: 2380

c++ fstream and seekp

If I do a seekp past the end of a file and then a write what happens? What I would like to happen is that the file would automatically be extended to the size of the seekp location. If so, does it also fill in the space between the old end of file and the new location by writing anything to the disk or is the space just allocated.

However, if it does not extend the file, how could I accomplish fairly efficiently?

Upvotes: 2

Views: 693

Answers (1)

NPE
NPE

Reputation: 500357

It is perfectly acceptable to seekp() past the end of file and then write. The file would indeed be extended.

Whether or not there would be disk space allocated for the hole depends on the filesystem. Some filesystems (e.g. ext3) support sparse files, some don't.

Upvotes: 2

Related Questions