Archived

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

writing float array to file

This topic is 5010 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



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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites