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 8604007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:27:42+00:00 2026-06-12T02:27:42+00:00

I currently write a class for some IO operations. Some functions return whether the

  • 0

I currently write a class for some IO operations. Some functions return whether the IO operation was successful. If I’m reading a file, I wonder if I should return std::ifstream::good() or !std::ifstream::fail() to indicate whether the IO operation was sucessful.

The difference comes from the eof bit and I’m not sure that I correctly understand it.

Suppose that I have a binary file with 4 bytes in it (1 integer).

Suppose that I read this integer.

My question is : will the eof flag be set after this operation or after the next IO operation (that will fail) ?

If it set directly after this operation, if my reading function return std::ifstream::good(), then the result will be false (but the integer was correctly read).

Can you explain me when the eof bit is set and what should I return at the end of my functions ?

  • 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-12T02:27:43+00:00Added an answer on June 12, 2026 at 2:27 am

    The EOF flag is set after you attempt to read over the end of the stream.

    Your function should return a reference to the original stream, and you should use it in a loop or in a conditional, like this:

    std::istream & process(std::istream & is)
    {
        int n;
        if (is >> n) { std::cout << "Read one int: " << n << "\n"; }
        return is;
    }
    
    int main()
    {
        std::ifstread infile("data.bin");
    
        while (process(infile)) { }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently tempted to write the following: public class Class1() { public Class1() {
I am currently trying to write some code that will accept some FTP details,
Currently ive got some reference counted classes using the following: class RefCounted { public:
I'm currently trying to write some classes and I come accross the following problem:
I am currently trying to write some flexible compile time mathematics library and just
I am currently trying to write some code which is going to send a
Currently plugins I write seem to work or not in random ways. Some do
My task is to write a class RFind which recursively searches the current directory
I'm currently trying to write a script that will connect to a site using
I'm currently trying to write an Artemis like game component/entity system in C++. I

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.