writing float array to file
anyone know a way to write a float array to file without splitting up the floats into characters?
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement