Archived

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

phongor

writing float array to file

Recommended Posts

CautionMan    122


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   
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