Where is cin?

In chapter 10 (input and output streams) of "Programming principle and practice using C++" in the part that manage bad input, i've found this function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int get_int(int low, int high)
{
      cout<<"Please enter an integer in the range "
          <<low<<" to "<<high<<" (inclusive:\n";

      while (true)
      {
      int n = get_int();
      if (low<=n && n<=high) return n;
      cout<<"Sorry "
          <<n<<" is not in the ["<<low<<':'<<high
          <<"] range; please try again\n";
      }
}


After this the book says:
"This get_int() is as stubborn as the other. It keeps getting ints from the non-range get_int() until the int it gets is in the expected range."

Now where is cin in this code?
i mean i can't see any command that allows the user to input something
Presumably the call to get_int() gets user input.
Thank you.

something like:

1
2
3
4
5
int x = 0;

while (cin>>x)

x = get_int(a, b);


Please correct me if this is wrong.

Thanks again
No, there are two functions named "get_int":

int get_int(); 
int get_int(int low, int high);

Find the source code for the first function -- it was probably introduced earlier in the book.

Good luck!
Last edited on
Topic archived. No new replies allowed.