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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:02:20+00:00 2026-06-13T02:02:20+00:00

My question is how does, while(cin>>x) { //code } work. Or to be more

  • 0

My question is how does,

while(cin>>x)
{
     //code
}

work. Or to be more specific, what about that code halts the loop?

From the documentation here, it looks like the >> operator returns a &istream. Does that mean if the read fails or hits the end of file it not only sets the eofbit, failbit or badbit but also returns a null? That doesn’t really make sense so I doubt that’s it.

Is there some kind of implicit check of the eofbit?

I ask because I’m hoping to implement something similar with 2 classes like this,

class B
{
   //variables and methods
}

class A
{
   //Variables and methods
   //Container of B objects. ex. B[] or vector<B> or Map<key,B>
   &A >> (B b);
}

int main()
{
   A a;
   B b;

   while( a >> b)
   {
      //Code
   }

}

Note: I’m not looking to inherit from istream unless it’s where the magic that makes this work come from. The reason for this is I’m hoping to keep the classes and their dependencies as small as possible. If I inherit from istream I will receive all its public and protected stuff and I’m not trying to create an istream like object. I just want to copy one REALLY nice piece of it.

Edit: I’m using Visual Studio 2010, (which is becoming a real pain) and I’m going to need something compatible with it’s implementation of C++03 + some C++11.

  • 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-13T02:02:22+00:00Added an answer on June 13, 2026 at 2:02 am

    Now could you write up an example of how I can do that with the above stuff?

    Like this:

    // UNTESTED
    class B
    {
       //variables and methods
    }
    
    class A
    {
       bool still_good;
    
       //Variables and methods
       //Container of B objects. ex. B[] or vector<B> or Map<key,B>
       A& operator>>(B& b) {
         try_to_fill_b();
         if(fail) still_good = false;
         return *this;
       }
       explicit operator bool() { return still_good; }
    }
    
    int main()
    {
       A a;
       B b;
    
       while( a >> b)
       {
          //Code
       }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i just got some more questions while learning PHP, does php implement any built
Question:- Does java client need to worry about multiple servers ? Meaning:- I have
Simple question: does the Java memory/synchronization model guarantee atomic pointer writes? That is, if
(This question does not rely on a specific IoC framework, so the interfaces and
So here's the scoop: I wrote a tiny C# app a while back that
earlier i posted a question about cin skipping input, and I got results to
I have a question about the difference between these two pieces of code: char
Intrigued by this question about infinite loops in perl: while (1) Vs. for (;;)
Or say does 1 denotes white for an RGB image? I have this question
[Question] Does anyone product release notes via an automated process? If so how. Especially

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.