C++ How to read in objects with a given offset?

shevron picture shevron · Jun 26, 2009 · Viewed 7.8k times · Source

Now I have a file with many data in it. And I know the data I need begins at position (long)x and has a given size sizeof(y) How can I get this data?

Answer

eduffy picture eduffy · Jun 26, 2009

Use the seek method:

ifstream strm;
strm.open ( ... );
strm.seekg (x);
strm.read (buffer, y);