Advertisement

Iinput/Output: Wierd Things

Started by August 23, 2001 01:07 PM
1 comment, last by parklife 23 years, 6 months ago
Hi there, I''m currently programming this small game that uses a 3d-array for the levels. However, I having some wierd errors when trying to read and/or write these levels from/to disk. It seems that when fout.write or fin.read hits tiles number 25 (End of medium) or 26 (End of file) they simply stop doing what they''re supposed too. I think this is very wierd. Please help! code: unsigned int city[2][15][21]; memset(&city,0,sizeof(city)); void SaveMap (char *filename) { ofstream fout(filename); fout.write((char*) &city, sizeof(city)); fout.close(); } void LoadMap (char *filename) { ifstream fin(filename); fin.read((char*) &city, sizeof(city)); fin.close(); } /john *Save GameDev - donate*
Solved it!

ofstream fout(filename,ios::binary);
ifstream fin(filename,ios::binary);

just change these two lines. I was stupid, for a while. Swept away, by you. and i feel like a fool. Still confused - my heart''s bruise.

erarr..ar..



/john
*Save GameDev - donate*
Advertisement
I just did that exact same thing last week:
"What, the file is 6k, why is it only reading 500 bytes? And where are these extra 17 bytes coming from when I write it out?"

(injures self smacking self on forehead.)

This topic is closed to new replies.

Advertisement