Jump to content
  • Advertisement

Archived

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

phongor

writing float array to file

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

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]

Share this post


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

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!