• Advertisement

Archived

This topic is now archived and is closed to further replies.

WHOAH. I've never seen this happen with saving files!

This topic is 5900 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is the wierdest thing and it took me all day to find this problem. However, I have no clue why it''s happening. Here''s some code: ofstream outfile; outfile.open(fileName, ios::app | ios::binary); for(int j = 0; j < 84; j++) { outfile.write((char*)(&tempInt), 1000); } outfile.close(); Pretty basic code. It creates a file and I''ve checked the size and it''s 84,000 bytes in size. So far, so good. Now if I change the write function to this: outfile.write((char*)(&tempInt), 10000); So that each write writes 10 times as much memory, I would expect a file of size 840,000 bytes. But get this. The file ends up being only 2,204 bytes. How in the world is this happening???? Please, ANY help would be appreciated. I am completely stuck and don''t know where to go. Thaks so much to anyone who replies. --Vic--

Share this post


Link to post
Share on other sites
Advertisement
From the STL doc on ostream::write
"The caller must ensure that str really contains at least count characters, otherwise the behavior is undefined."

Share this post


Link to post
Share on other sites
quote:
Original post by Fruny
From the STL doc on ostream::write
"The caller must ensure that str really contains at least count characters, otherwise the behavior is undefined."


Whats the website of the STL doc?

Share this post


Link to post
Share on other sites
Hmm... that''s not from a website, that''s from a book.

I don''t know if there''s a reference online. You can go check SGI''s website (SGI''s implementation of the STL is among the most popular)

http://www.sgi.com/tech/stl/

Share this post


Link to post
Share on other sites

  • Advertisement