Jump to content
  • Advertisement

Archived

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

Python

Loading binary datas

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

Hello all, I''m wondering how to load binary-datas. I found some routines working with "ofstream". The code to store the files goes like this: ofstream fout("nice.nd",ios::binary); fout.write((char*)&BFile,sizeof(BFile)); fout.close(); (While BFile is an Array of DirectX-vectors) So, that works fine, but I didn''t found out how to read the datas. Does anyone got experience with that ... I think I''m getting mad .. ;-) Thank you in advance, :-) Python Spin the wheel of fortune - or learn to navigate.

Share this post


Link to post
Share on other sites
Advertisement
There are a lot of tuts on reading and writing files that I''m sure you could use... but basically you need to use an ifstream and read in the data. You''ll need to figure out the size of what you''re reading. For example:


  
// read a file into memory

#include <iostream>
#include <fstream>
using namespace std;

int main () {
int length;
char * buffer;

ifstream is;
is.open ("test.txt", ios::binary );

// get length of file:

is.seekg (0, ios::end);
length = is.tellg();
is.seekg (0, ios::beg);

// allocate memory:

buffer = new char [length];

// read data as a block:

is.read (buffer,length);

is.close();

return 0;
}


this is taken from www.cplusplus.com

This will hopefully get you started.

Share this post


Link to post
Share on other sites
That really helped.

Thanks a lot and have a nice day in coding!

:-) Python

Spin the wheel of fortune - or learn to navigate.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!