Sign in to follow this  
ganbree

File Streams

Recommended Posts

Hi everyone, I'm creating a lump file class and I need to know more about std::ifstream. When I use the constructor that auto calls open or open itself does it load the entire file into memory? Also, how can I read from a particular number of bytes into the file?

Share this post


Link to post
Share on other sites
Quote:
Original post by ganbree
When I use the constructor that auto calls open or open itself does it load the entire file into memory?

This depends on the implementation and the size of the file being opened, but generally, no. It'll read from the file as necessary as you call operations on the file stream.
Quote:

Also, how can I read from a particular number of bytes into the file?

Did you try the read() member function?

Share this post


Link to post
Share on other sites
Thank you. That complicates things.

However, read() does not let me set from where in the file to read. I've found fstream::seekg() from my DerivedClass::GetFileSize (copied from an earlier project), I think thats the answer.

Case solved. ~ish

Share this post


Link to post
Share on other sites
Quote:
Original post by ganbree
Thank you. That complicates things.

However, read() does not let me set from where in the file to read. I've found fstream::seekg() from my DerivedClass::GetFileSize (copied from an earlier project), I think thats the answer.

Case solved. ~ish


C++ STL Reference

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