Wednesday, April 25, 2007

As accessing binary data (either writing and reading, basically the reading part of it) was tedious with PERL.
I thought C++ will help me with it. Initially, I was having to deal with the last data element being stored twice. This is now resolved....

The sample code is as:

// writing and reading a binary data
//
#include
#include
using namespace std;

// gives nice explaination on reading and writing a binary file
// ref: http://www.gamedev.net/reference/articles/article1127.asp
// http://courses.cs.vt.edu/~cs2604/spring06/binio.html
//
int main() {

// data to be written to a file
//
float arr[4] = {10.234, 1.212, 0.2, 342};

ofstream outfile("test1.raw", ios::out | ios::binary);

cout << "writing to a file " << i =" 0;" j =" arr[i];"> float data1[4];
and have --> myfile.read( (char *) &data1, sizeof(data1));
to access the data..

No comments: