Sign in to follow this  
Servant of the Lord

std::ifstream::read() failing to read all the bytes.

Recommended Posts

swiftcoder    18432

When I seeked to the end of the file, it told me the number of bytes.
But when I read the file into my buffer, it combined the two line-ending characters into one, which counted as a single byte.

This problem becomes infinitely worse when you try to read a variable-length character encoding, like, say, UTF-8 :)

 

For the simple case you describe, I usually default to calling std::getline() in a loop...

Share this post


Link to post
Share on other sites

That's what I do in my (unmentioned) LoadFileAsStringList() function because it returns the contents as a std::vector<std::string>, but for most of my usage I actually want the newlines intact (though I could do without the carriage returns!).

 

I've never dealt with unicode before, but from what I've heard, I can look forward to not enjoying it. laugh.png

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