• Advertisement
Sign in to follow this  

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

This topic is 1790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

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
Sign in to follow this  

  • Advertisement