Difference between pressing space and enter while giving input

Please explain..

Say I'm giving 7 8 9 as my input..
7 "press space" 8 "press space" 9 "now press enter" you get the output as 789

now 7 "press enter" gives output as 7
8 "press enter" gives output as 8
9 " press enter" gives output as 9

Knowing that cin considers spaces as terminating the value being extracted..Please explain what's happening

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;

int main()
{
    int foo[3];
    
    for(int i=0; i<3; i++)
    {
        cin>>foo[i];
        cout<<foo[i];
    }
    
    system("pause");
    return 0;
}


A majority of consoles do not send input to the program until you press enter - this is to allow you to backspace and fix mistakes. Aside from this, there is no difference between a newline and a space in the eyes of the formatted input operator >>

See also:
http://www.lb-stuff.com/user-input
Thanks LB!
Topic archived. No new replies allowed.