Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:33:46+00:00 2026-06-17T20:33:46+00:00

So, I am curious as I’ve been using this rather useful approach to get

  • 0

So, I am curious as I’ve been using this rather useful approach to get the size of the file, but something bothers me. Locking a stream to a file on the file system and

fileStream.seekg(0, std::ios::beg);
int beginning = fileStream.tellg();

yields 0. That’s to be expected, we use the benefits of zero-based counting. What is interesting to me is that a file of 512 bytes would have positions in the range of [0, 511], therefore, returning the value of

fileStream.seekg(0, std::ios::end);
int end = (int)fileStream.tellg(); // We don't care for +4GB here

should yield 511 for end, because that’s the last byte. The last position within the file loaded. So any buffer used to read in the stream would only get 511 bytes, rather than 512 bytes.

But it works, so you can see my confusion. What gives? I’m at a loss. Where does the +1 come?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:33:47+00:00Added an answer on June 17, 2026 at 8:33 pm

    After,

    fileStream.seekg(0, std::ios::end);
    

    the file pointer is position just after the last byte (#511). This is what the number 512 indicates. Here, 511 would mean just before the last byte.

    Let’s consider a file that’s two bytes long:

    • position 0 is before the first byte;
    • position 1 is before the second byte;
    • position 2 is before the (non-existent) third byte, i.e. at the end of the file.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Curious as to how to approach this same problem using ruby / rails -
Curious if anyone ever noticed this, but I have a WYSIWYG that users occassionally
Curious if anyone can help me on this. I am using WooThemes to create
Curious question: Take this function: function something():Array { var ar:Array = []; var i:MovieClip;
Curious if anything jumps out here. But when I run this code block :
Just curious after reading this , it wraps django using tornado. Is there any
Just curious to know what the best practice would be for something like this:
Curious if I'm doing this right and if not how you guys would approach
Curious, what happens when you return keyword this from a struct in C#? For
Curious what "Toast" means? Saw this and am curious... Similar Posts How to add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.