Results 1 to 2 of 2

Thread: saving objects to disk

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    saving objects to disk

    I have a 2 dimensional array which holds vectors of floats, its pretty big and i need save and restore this from disk.

    Is there an easy way to do this other than reading it in and out of text files?

    Cheers

    Andy

  2. #2
    jim mcnamara
    Guest
    use fread() fwrite() to write a binary file.

    Code:
    FILE *out;
    float  **arr;
    ... fill up your array with data
    out=fopen("myfile.dat","wb");
    fwrite(arr, sizeof(float), numberofelements, out);
    fclose(out);
    
    // to get it back -
    out=fopen("myfile.dat","rb");
    fread(arr,sizeof(float), numberofelements,out);
    fclose(out);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width