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


Loading binary datas

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
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; ("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: (buffer,length);


return 0;

this is taken from

This will hopefully get you started.

Share this post

Link to post
Share on other sites