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

Started by
2 comments, last by Roof Top Pew Wee 22 years, 4 months ago
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--
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."
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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?
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/
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement