writing float array to file

Started by
4 comments, last by phongor 20 years, 1 month ago
anyone know a way to write a float array to file without splitting up the floats into characters?
Advertisement
void WriteFloatArray(float *floatArray, int numberOfItems, string filename){   ofstream fileOut(filename.c_str(), ofstream::out | ofstream::trunc | ofstream::binary);   fileOut.write((char*)floatArray, numberOfItems * sizeof(float));   fileOut.close();}void ReadFloatArray(float *floatArray, int numberOfItems, string filename){   ifstream fileIn(filename.c_str(), ifstream::in | ifstream::binary);   fileIn.read((char*)floatArray, numberOfItems * sizeof(float));   fileIn.close();}


For more info, go to www.cplusplus.com and punch "ofstream" or "ifstream" into the quick search.

Edit: fixed a syntax error (oops..).

[edited by - CautionMan on March 28, 2004 6:11:09 PM]
thanks thats seems to work ok, i thought i was gooing the have to split up the 4 bytes of the float into four chars.
doesn''t work, data is lost
quote:Original post by phongor
doesn''t work, data is lost


That should work, there must be some kind of error elsewhere in your program.

your right it does work was another error, thanks a bunch

This topic is closed to new replies.

Advertisement