3
#include<iostream>

int main()
{
    std::cout << "Enter two numbers:" << std::endl;
    int v1 = 0, v2 = 0;
    std::cin >> v1 >> v2;
    std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1 + v2 << std::endl;
    return 0;
}

If the input given is 5 6, it'll print "The sum of 5 and 6 is 11". But how does the istream know when to stop?

Does it keeps on taking input if its an integer and stops if it gets another data type?

How does it assign the correct values of v1 and v2?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Deepak Pawade
  • 150
  • 1
  • 13

1 Answers1

4

(>>) is an extraction operator. It can be used more than once to accept multiple inputs. It differentiates the multiple inputs through spaces or the next line. In your case, there is a space between 5 and 6 so the extraction operator will assign 5 for v1 and 6 for v2.