Sign in to follow this  
jazztuffy

reading file from certain position

Recommended Posts

hi guyz, Iam dumpin g a matrix into a binary file. And i am reading it. I need to take sinfle element at a time and read it. If there is any way i can read entire matrix at a time please lemme know. Else how can i start readin the file from certain position like the number width is abt 7 charecter. so hw can i go abt starting from 8 charecter for next element. Please guide me thank you

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Why not just...

fread (buffer,1,sizeof(MyMatrixClass),pFile);

To move within file you need call fseek..

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Why not just...

fread (buffer,1,sizeof(MyMatrixClass),pFile);

To move within file you need call fseek..


This will work as long as MyMatrixClass does not have any virtual functions or inherit from a class that has virtual functions. If it did, then the compiler will add a hidden pointer to the class to reference the vtable.

Share this post


Link to post
Share on other sites
Yeah I actually added that as an edit but it didn't let me add it as I was logged in as anon when I posted... :)

If you need to stream memory images of classes that have virtual function you have to invoke the in-place new constructor... (and make sure your c'tor doesn't overwrite any of the streamed values).

Also if your matrix class DOES have virtual functions then you are in for a world of hurt anyway :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this