I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » New Module Ideas »

will\′s Photo
24 Sep 05, 5:24PM
Hi,

Thats a great idea. If I understand you correctly, then this shouldn't be too hard. Using the [b:7a32f5d626]sizeof[/b:7a32f5d626] operator, you will know exactly how big a binary variable is, and therefore where in a file any particular item will be into that file.

Something like (sorry I'm used to the C style for files!)

template <class T>
class binaryio
{
  FILE* stream;
 
  binaryio(char* filename)
  {
    stream = fopen(filename, "b");
  }
 
  T operator [](int i)
  {
    fseek(stream, i * sizeof(T), 0);   //<- Can't remember the syntax here. 
    T data;
    fread(&data, 1, sizeof(T), stream);
    return data;
  }
};

And something smarter to write back to random locations..

Is that what you're think?

Currently you need to be logged in to leave a message.