|
-
February 4th, 2009, 02:02 PM
#7
Re: Difference between ostream and ofstream
But when I store the header using ofstream, I can seek behind EOF, and that's where the confusion started...
Don't be confused by what you can do, be confused by what you can't do 
I have have never used ofstream so I don't know why you can write beyond it's actual size, but I do know that with a 'normal' file you can't because there is nothing to go beyond. They only thing I can 'guess' is that if you seek beyond eof and you start writing, ofstream automatically fills it with '\0' chars. To be sure, simply try it and see what happens.
1. How do I extend the file to be 110 bytes? Do I just write additional 10 '\0' symbols?
yes.
2. If I later write to those 10 bytes, it will not increase the size of the file, right?
As soon as you write the '\0' from question 1, the file size will increase. If you later on overwrite those 10 bytes with other data, the size will not increase.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|